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);
}
}