BroadcastReceiver.onReceive called twice for user_present

I have a strange problem (?), I implemented BroadcastReceiver for USER_PRESENT , it works fine on my tablet, but it runs twice on my Galaxy S, can someone shed some light here?

 <receiver android:name="XYZBroadcastReceiver" > <intent-filter> <action android:name="android.intent.action.USER_PRESENT"/> </intent-filter> </receiver> 

I have a simple statement in the onReceive method and it prints twice, in the logarithm I see the following twice:

 11-23 17:36:35.603: INFO/Launcher(2632): ACTION_USER_PRESENT 
+4
source share
3 answers

You may have installed the application on your device twice (the broadcast receiver exists in towing different applications).

Check and uninstall the entire test application. Then run the test and check if the log statement is printed in the log. Then install the application and see what happens.

Hope this helps you.

0
source

Well, in the absence of any answer in time I had to move forward, and I came up with a job. Work on the fact that I check db and make sure that the time difference between the two events is at least> = 1

Thus, whenever a quick call is made (which is happening only now in Galaxy s), no action is taken for the second quick call.

0
source

I made this decision. I created a simple semaphore. create an open class

 public class Global { public static Boolean IS_RUNNING= false; } 

and in BroadcastReceiver

 public class ConnectivityReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Global.IS_RUNNING){ //allready running!!! do nothing return; } Global.sendToLog("run the update"); ... do stuff, in the end set Global.IS_RUNNING=false; } 

}

0
source

Source: https://habr.com/ru/post/1382815/


All Articles