Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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_Android Activity - Fatal编程技术网

解锁android设备时重新启动活动

解锁android设备时重新启动活动,android,android-activity,Android,Android Activity,在我的android应用程序中,我使用广播接收器启动活动。如果我的设备在此活动期间锁定,并且如果我将其解锁,则“活动重新启动”意味着它将在“创建”上再次运行 请帮我解决这个问题 提前感谢您在AndroidManifest.xml中的活动声明是什么? 我认为您应该指定launchMode为“singleTask”,如下所示: <activity android:name=".Youracticity" android:launchMode="singleTask" android:confi

在我的android应用程序中,我使用广播接收器启动活动。如果我的设备在此活动期间锁定,并且如果我将其解锁,则“活动重新启动”意味着它将在“创建”上再次运行 请帮我解决这个问题


提前感谢

您在AndroidManifest.xml中的活动声明是什么? 我认为您应该指定launchMode为“singleTask”,如下所示:

<activity android:name=".Youracticity" android:launchMode="singleTask" android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait">
</activity>


^-^

在您的舱单中是否有类似的内容:

<action android:name="android.intent.action.USER_PRESENT" />

        <receiver android:name="com.activities.app" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>


如果是,请正确处理。

要检测屏幕打开和屏幕关闭,请注册广播接收器,如:

<receiver android:name="receiverScreen">
    <intent-filter> 
        <action android:name="android.intent.action.SCREEN_ON" />
        <action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.Intent.ACTION_USER_PRESENT" />
    </intent-filter> 
</receiver>
try {
          IntentFilter if= new IntentFilter(Intent.ACTION_SCREEN_ON);

          if.addAction(Intent.ACTION_SCREEN_OFF);
if.addAction(Intent.ACTION_USER_PRESENT);

          BroadcastReceiver mReceiver = new receiverScreen();

          registerReceiver(mReceiver, if);
     } catch (Exception e) {

     }
public class receiverScreen extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {

     if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){

     }
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){

     }
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){

     }
 }

}
系统在屏幕打开/关闭时通知您的接收器代码:

<receiver android:name="receiverScreen">
    <intent-filter> 
        <action android:name="android.intent.action.SCREEN_ON" />
        <action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.Intent.ACTION_USER_PRESENT" />
    </intent-filter> 
</receiver>
try {
          IntentFilter if= new IntentFilter(Intent.ACTION_SCREEN_ON);

          if.addAction(Intent.ACTION_SCREEN_OFF);
if.addAction(Intent.ACTION_USER_PRESENT);

          BroadcastReceiver mReceiver = new receiverScreen();

          registerReceiver(mReceiver, if);
     } catch (Exception e) {

     }
public class receiverScreen extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {

     if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){

     }
    if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){

     }
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){

     }
 }

}

您是否实现了
onPause()和/或
onStop()方法?如果是,您是否正在保存应用程序状态?你们使用的是什么设备?我在create方法中添加了toast,每次解锁时都会得到toastdevice@chester1000我应该保存哪个应用程序状态以及如何通过使用它来防止?现在我在使用此解决方案后遇到了一个问题。在活动中,我全屏显示视频,但在解锁设备后,视频无法全屏显示