简体   繁体   English

按下“主页”按钮并按下图标(在启动器上)后,应用程序重新启动

[英]After Home button pressed and pressed icon (on launcher) app restart

If install app from sd by default installer and Open button pressed will open app. 如果默认情况下从sd安装应用程序,并且按下“打开”按钮将打开应用程序。 After Home button pressed and click icon (on launcher) app will restart. 按下“主页”按钮并单击图标(在启动器上)后,应用程序将重新启动。 Need kill app from memory and start by icon on launcher for normal behaviour. 需要从内存中杀死应用程序,并通过启动器上的图标启动才能正常运行。

Steps: 脚步:
1. Create simple app 1.创建简单的应用
2. Load to sd 2.加载到SD
3. Install and Open from installer 3.从安装程序安装并打开
4. Change any behavior 4.改变任何行为
5. Pressed Home button 5.按下主页按钮
6. Pressed icon app on launcher 6.在启动器上按下图标应用程序
7. App restarting ! 7.应用重启!

If kill app from memory and run by icon on launcher will behavior is normal. 如果从内存中杀死应用程序并通过启动器上的图标运行,则行为正常。 How do it resolve it? 如何解决呢?

I solved this issue with the following code in the onCreate() method: 我使用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(); 
    } 
} 

Opposed to other proposed solutions, this does not require the declaration of "android.permission.GET_TASKS" 与其他建议的解决方案相反,这不需要声明"android.permission.GET_TASKS"

Please check for the flag android:launchMode for activity in Android Manifest. 请检查Android清单中活动的标志android:launchMode。 Try deleting it and check. 尝试删除它并检查。

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

相关问题 android手机按下home键后如何避免应用重启 - How to avoid app restart after pressed home button in android phone 按下主页按钮重新启动我的应用程序活动 - restart my app activity on home button pressed 如何在按下HOME按钮后立即重新启动相同的活动? - How to restart same Activity immediately after HOME button is pressed? 如何在按下主页按钮时不重启我的应用程序? - How to not restart my app when the Home button is pressed? 按下“主页”按钮后,从点击图标应用程序再次启动我的活动后,我的活动不会重新加载 - After Home button pressed, my Activity not reload when launch it again from click icon app 按下主页后,应用程序崩溃 - App crashes after home is pressed 按下主页按钮后重新启动应用程序时,不会调用 onResume - onResume is not called when I relaunch the app after home button pressed 按下主页按钮并返回应用程序后如何恢复以前的活动 - How to restore previous activity after pressed home button and return to the app Flutter 启动器:Go 按下主页按钮时返回主页屏幕 - Flutter Launcher: Go back to the HomeScreen when Home Button is pressed Android libgdx:启动器图标按下后,启动屏幕不立即显示 - Android libgdx: splash screen not showing immediately after launcher icon pressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM