android:nohistory标志被忽略
以下是场景:android:nohistory标志被忽略,android,android-intent,android-activity,android-lifecycle,android-task,Android,Android Intent,Android Activity,Android Lifecycle,Android Task,以下是场景: 用户使用Activity#1计划报警(使用androidAlarmManager服务),然后返回主屏幕。活动#1仍在堆栈中 AlarmReceiver的onReceived()按计划调用: @Override public void onReceive(Context context, Intent intent){ Intent intent = new Intent(context ,Activity2.class); intent.setFlags(
AlarmManager
服务),然后返回主屏幕。活动#1仍在堆栈中AlarmReceiver
的onReceived()
按计划调用:
@Override
public void onReceive(Context context, Intent intent){
Intent intent = new Intent(context ,Activity2.class);
intent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_NO_HISTORY
);
context.startActivity(intent);
}
Activity2
)成功启动
public class Activity2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout_2);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
}
@Override
protected void onResume() {
super.onResume();
findViewById(R.id.dismiss_button).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
}
);
}
}R.id.disease_按钮
)以finish()
活动#2Intent.FLAG\u ACTIVITY\u NO\u HISTORY
标志外,该标志也在AndroidManifest.xml
中指定(我还分别尝试了它们):
此外,还需要标记
Intent。标记活动
新任务
,因为活动2是从报警接收器
启动的,而不是从另一个活动启动的。无历史记录标记只是在活动
不再可见时防止该活动
出现在任务堆栈中。在您的情况下,如果在显示Activity2
时按HOME键,您将看到Android立即对该活动调用finish()
和onDestroy()
(这不是将任务置于后台时的常见行为)
要想做你想做的事,你需要添加
android:excludeFromRecents="true"
到
活动的清单条目
。这告诉Android不要将您的任务放在最近的任务列表中。不知道Android:excludeFromRecents。谢谢
android:excludeFromRecents="true"