문제

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