当活动从服务开始时,如何关闭最近的活动(按住主页按钮)?
试过android:excludeFromRecents="true"
and android:noHistory="true"
,但如果我从myActivity
. 但是,当使用 关闭finish()
服务时Broadcast Receiver
,它不起作用。
那么,当它从服务中自动关闭时,如何关闭最近的活动呢?请帮忙 。.
当活动从服务开始时,如何关闭最近的活动(按住主页按钮)?
试过android:excludeFromRecents="true"
and android:noHistory="true"
,但如果我从myActivity
. 但是,当使用 关闭finish()
服务时Broadcast Receiver
,它不起作用。
那么,当它从服务中自动关闭时,如何关闭最近的活动呢?请帮忙 。.
实际上,您必须清除活动堆栈内容。在 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);
这适用于最近应用程序的清晰历史记录:
android.os.Process.killProcess(android.os.Process.myPid());