总是推出新的活动实例与没有历史 [英] Always launch new activity instance with no history
问题描述
有没有办法启动的活动与没有历史的新实例?
Is there a way to launch an activity as a new instance with no history?
试过在清单文件如下。
android:launchmode="singleinstance"
android:noHistory=true
我能够实现我需要什么,但只要在屏幕锁定的previous活动显示。这就是 noHistory
是应该做的,但不是我所需要的。
I am able to achieve what I need, but as soon as the screen is locked the previous activity is displayed. That's what noHistory
is supposed to do, but not what I need.
保持在屏幕上永远不会是preferable,因为它会耗尽电池不必要的。有没有开始一个新的实例,一个活动,没有历史,而且当屏幕被锁定工作任何其他的方式?
Keeping the screen on always would not be preferable as it would drain the battery unnecessarily. Is there any other way to start an activity with a new instance and have no history but also work when the screen is locked?
推荐答案
这将开始与新的信息和病史
This will start a activity with new information and no history
Intent intent = new Intent(MainActivity.this, TargetActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
MainActivity.startActivity(intent);
这篇关于总是推出新的活动实例与没有历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!