Recently in the company processing projects, using the lock screen status popup activity to prompt, similar to QQ message popup function. When used, if the popup activity is already located outside the lock screen, will not play the window again, but send the broadcast to notify the data update, but in the broadcast receiver in a step to send a notification again operation, found that the broadcast receiver becomes a dead loop execution. After careful examination, it was found that there was no wrong action in any place. Finally, the broadcast in the receiver to send the broadcast statement comments, the dead loop is not. The code is as follows:
Note: All the actions inside are carefully checked, used correctly, with no errors, or reference errors.
Package com.guc.doctorwarn.receiver;
Import com.guc.doctorwarn.LocalScreenMessageActivity;
Import Com.guc.doctorwarn.utils.WakeLock;
Import Com.library.helper.AppIsBackground;
Import Com.library.util.PreferencesUtil;
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import Android.util.Log;
/**
* This broadcast is used to receive the lock screen prompt broadcast
*
* @author Administrator
*
*/
public class Localscreenmessagereceiver extends Broadcastreceiver {
public static final String localscreenmessageaction = "Com.guc.doctorwarn.LocalScreenMessageAction";
@Override
public void OnReceive (context context, Intent Intent) {
/**
* If the app is in the background, unlock the ScreenTip or do not prompt
*/
LOG.I ("A", ">>> lock screen message broadcast receiver received message <<<");
LOG.I ("a",
">>> whether the app is in the background <<<"
+ Appisbackground
. Isapplicationbroughttobackground (context));
if (Intent.getaction (). Equals (Localscreenmessageaction)) {
if (Appisbackground.isapplicationbroughttobackground (context)
&&! Preferencesutil.getboolean (Context, "screen")) {
Wakelock.acquirecpuwakelock (context);
Intent localmessage = new Intent ();
Localmessage
. SetClass (context, localscreenmessageactivity.class);
Localmessage.setflags (Intent.flag_activity_clear_top);
Localmessage.addflags (Intent.flag_activity_new_task);
Context.startactivity (Localmessage);
} else if (! Appisbackground
. Isapplicationbroughttobackground (context)
&& Preferencesutil.getboolean (context, "screen")) {
Intent updatamessage = new Intent ();
Updatamessage
. Setaction (Localscreenmessageactivity.uplocalmessagedataaction);
Context.sendbroadcast (Intent);
//
LOG.I ("A", "Broadcast update lock screen activity execution");
}
}
}
}
Summary: In the Android development process, the broadcast receiver can not send the broadcast again, or the operation of the broadcast receiver will enter a dead loop state.
Android broadcasts a broadcast in the broadcast receiver Broadcastreceiver, causing the current broadcast receiver to continually loop through the problem