1

I have a LockScreenReceiver extend BroadcastReceiver class, and want to start Lock Screen Intent every time the screen has been turn off. But how can I check the Context has been start the given activity already, so I don't have to start it all over again.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        isScreenOn = false;
        LockServiceManager.getInstance().Initialize(context);
        Intent lockIntent = LockServiceManager.getInstance().getLockScreenActivityIntent();
        lockIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockIntent);
    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        isScreenOn = true;
        // TODO Start activity if the device has been sleep for a long time.
    } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Intent lockIntent = LockServiceManager.getInstance().getLockScreenActivityIntent();
        lockIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(lockIntent);
    }
}
Edward Chiang
  • 1,133
  • 2
  • 12
  • 24

1 Answers1

1
public void onResume(){   
 Filter = new IntentFilter();
    Filter.addAction("RECEIVED_ACTION");
    activity.registerReceiver(Receiver, Filter);
}

I hope it is useful for you.

dipali
  • 10,966
  • 5
  • 25
  • 51