0

私の Android アプリケーションでは、ブロードキャスト レシーバーを使用してアクティビティを開始しています。このアクティビティ中にデバイスがロックされ、ロックを解除した場合、アクティビティを再開すると、作成時に再び実行されることを意味します この問題の解決を手伝ってください

前もって感謝します

4

3 に答える 3

1

AndroidManifest.xml でのアクティビティ宣言は何ですか? そのようにlaunchModeを「singleTask」に指定する必要があると思います:

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

^-^

于 2012-08-01T09:07:23.783 に答える
0

画面オンと画面オフを検出するには、次のようなブロードキャストレシーバーを登録します。

<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)){

     }
 }

}
于 2012-08-01T09:24:08.600 に答える
0

あなたのマニフェストには、次のようなものがありますか?

<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>

もしそうなら、それを適切に処理してください。

于 2012-08-01T09:15:08.437 に答える