【问题标题】:After Home button pressed and pressed icon (on launcher) app restart按下主页按钮并按下图标(在启动器上)后,应用程序重新启动
【发布时间】:2017-09-24 22:27:15
【问题描述】:

如果默认安装程序从 sd 安装应用程序并按下打开按钮将打开应用程序。按下主页按钮并单击图标(在启动器上)后,应用程序将重新启动。需要从内存中杀死应用程序并通过启动器上的图标启动正常行为。

步骤:
1. 创建简单的应用程序
2.加载到sd
3. 从安装程序安装并打开
4. 改变任何行为
5.按下主页按钮
6. 启动器上的按下图标应用程序
7.应用重启!

如果从内存中杀死应用程序并通过启动器上的图标运行,则行为是正常的。 怎么解决的?

【问题讨论】:

    标签: android restart android-homebutton


    【解决方案1】:

    请检查标志 android:launchMode 以了解 Android Manifest 中的活动。尝试删除它并检查。

    【讨论】:

    • 这正是我的问题,启动器 Activity 有 launchMode:singleInstance。删除它解决了这个问题。
    【解决方案2】:

    我在onCreate() 方法中使用以下代码解决了这个问题:

    if (!isTaskRoot()) { 
        final Intent intent = getIntent(); 
        final String intentAction = intent.getAction(); 
        if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && 
                intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) { 
            finish(); 
        } 
    } 
    

    相对于其他提议的解决方案,这个不需要"android.permission.GET_TASKS"的声明

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多