Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何知道从上下文开始了哪些活动?_Android_Broadcastreceiver_Screen Lock - Fatal编程技术网

Android 如何知道从上下文开始了哪些活动?

Android 如何知道从上下文开始了哪些活动?,android,broadcastreceiver,screen-lock,Android,Broadcastreceiver,Screen Lock,我有一个LockScreenReceiverextendBroadcastReceiver类,每次屏幕关闭时都想启动锁屏意图。但是我如何检查上下文是否已经启动了给定的活动,这样我就不必重新启动它了 @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { isScreenOn = f

我有一个
LockScreenReceiver
extend
BroadcastReceiver
类,每次屏幕关闭时都想启动锁屏意图。但是我如何检查
上下文
是否已经启动了给定的活动,这样我就不必重新启动它了

@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);
    }
}
我希望它对你有用


我希望它对你有用。

你在找这个吗?如果你的报警接收器调用Context.startService()…[我希望它对你有用。你在找这个吗?如果你的报警接收器调用Context.startService()…[我希望它对你有用。
public void onResume(){   
 Filter = new IntentFilter();
    Filter.addAction("RECEIVED_ACTION");
    activity.registerReceiver(Receiver, Filter);
}