私の Android アプリケーションでは、ブロードキャスト レシーバーを使用してアクティビティを開始しています。このアクティビティ中にデバイスがロックされ、ロックを解除した場合、アクティビティを再開すると、作成時に再び実行されることを意味します この問題の解決を手伝ってください
前もって感謝します
私の Android アプリケーションでは、ブロードキャスト レシーバーを使用してアクティビティを開始しています。このアクティビティ中にデバイスがロックされ、ロックを解除した場合、アクティビティを再開すると、作成時に再び実行されることを意味します この問題の解決を手伝ってください
前もって感謝します
AndroidManifest.xml でのアクティビティ宣言は何ですか? そのようにlaunchModeを「singleTask」に指定する必要があると思います:
<activity android:name=".Youracticity" android:launchMode="singleTask" android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait">
</activity>
^-^
画面オンと画面オフを検出するには、次のようなブロードキャストレシーバーを登録します。
<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)){
}
}
}
あなたのマニフェストには、次のようなものがありますか?
<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>
もしそうなら、それを適切に処理してください。