android - 具有 Intent.FLAG_ACTIVITY_NEW_TASK 的 Activity 已被销毁

标签 android service android-activity background

如果我的应用程序在后台,我正在使用这种方式从服务启动 Activity :

        Intent intent = new Intent(this, FromBackgroundActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

它运行完美, 但是如果 FromBackgroundActivity 处于 Activity 状态并且我按下 Home 键,它会将所有内容置于背景中。 如果我在任务栏中单击我的应用程序,它会将我的应用程序恢复到前台但没有 FromBackgroundActivity,它会被销毁。 ( 如何使用 FromBackgroundActivity 从后台恢复我的应用程序?

最佳答案

试试 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));

它将清除所有任务并转到 FromBackgroundActivity。

关于android - 具有 Intent.FLAG_ACTIVITY_NEW_TASK 的 Activity 已被销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19048360/

相关文章:

android - Lokhttp3/internal/Util 类中没有静态方法 delimiterOffset

android - 通过命令行更改程序包名称(不使用Android Studio)

c# - 将控制台应用程序转换为 Windows 服务

android - 启动和停止服务

javascript - 从 ForEach 循环访问父对象的方法

android - savedInstanceState 始终为 null,但始终调用 onSaveInstanceState()

android - 将多个字符串传递给其他 Activity

java - Android studio 推送通知错误

android - 2D Sprite 的 OpenGL ES 投影

java - View.getWidth() 显示正确的宽度,但在添加到 View 的 x 位置时无法产生右边距