简体   繁体   English

android:当活动从服务开始时如何关闭最近的活动

[英]android: how to close recent activities when activities start from service

How to close recent activities(press and hold button home) when activity started from services? 从服务开始活动时如何关闭最近的活动(按住主页按钮)?

Tried android:excludeFromRecents="true" and android:noHistory="true" , but it works if I close manual from myActivity . 尝试使用android:excludeFromRecents="true"android:noHistory="true" ,但如果我从myActivity关闭手册, myActivity But, when close finish() from services using Broadcast Receiver , it doesn't work. 但是,当使用Broadcast Receiver从服务中关闭finish()时,它将不起作用。

So, how to close recent activities when it close automatic from services? 那么,如何从服务自动关闭最近的活动呢? Please help . 请帮忙 。 .

这适用于来自最近应用程序的清除历史记录:

android.os.Process.killProcess(android.os.Process.myPid());

Actually you have to clear the activity stack content. 实际上,您必须清除活动堆栈内容。 In API level 11 or greater, use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK flag on Intent to clear all the activity stack. 在API级别11或更高级别中,在Intent上使用FLAG_ACTIVITY_CLEAR_TASK和FLAG_ACTIVITY_NEW_TASK标志来清除所有活动堆栈。

    Intent i = new Intent(OldActivity.this, NewActivity.class);
// set the new task and clear flags
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(i);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM