有两项活动ActivityA
和ActivityB
,两者都是singleTask
。此处 ActivityB 属于HOME
类,并且始终设置为。我从BroadcastReceiver
ACTION_BOOT_COMPLETED
开始 ActivityA ,它按预期启动 ActivityA ,但 HOME KEY 是按下( ActivityB ), ActivityA 即被销毁
可能的原因是什么?如何阻止 ActivityA 被销毁?保持两项活动singleTask
。
这是BroadcastReciever:
public class MyStartupIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED == intent.getAction()) {
Intent i = new Intent(context, ActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
}
}
清单文件如下:
<activity
android:name="ActivityB"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="ActivityA"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity>