سؤال

So I have a slider in my android application. When I move it to the ON position, I send a broadcast two broadcasts to my background application.

The first broadcast on receive creates/deletes a file depending on the key/value pair in the broadcast. The second broadcast on receive checks to see if the file exists or not. If it exists, it executes some code. My code for sending the broadcasts is

Intent updateFile = new Intent();           
updateFile.setAction("com.example.makefile");   
updateFile.putExtra("enable", create);          
sendBroadcast(updateFile);

Intent startCode = new Intent();            
startMWC.setAction("com.m87.dev.start");    
sendBroadcast(startCode);

I was wondering whether it was possible for the second broadcast to be received first? As in, can there be a case where it checks to see whether the file exists or not before the file has been created?

I've thought about moving the second broadcast to the onReceive for the first broadcast but I don't always want it to be executed which is why I have it like so.

هل كانت مفيدة؟

المحلول

I was wondering whether it was possible for the second broadcast to be received first?

Yes, it's possible, because sendBroadcast is asynchronous.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top