How to prevent custom home launcher app restart activity?

隐身守侯 提交于 2019-12-18 04:23:07

问题


I am working on my own home launcher replacement and it works fine but one thing bothers me. When I press a home key, current home activity (the one defined in manifest as main/defualt/launcher/home) restarts - current activity instance onpause is executed and oncreate is fired again, so new activity is brought up.

On the other hand, ADW launcher and LauncherPRo does not behave like that - I do not a refresh like in my case. Launcher Pro even can do several actions:

  1. If you are on the main screen with app icons, it zooms out to see a snapshot of all screens,
  2. If you open a drawer and press Home, it just go back to the main screen.

Any ideas how to do that?

I just did a very simple prototype from scratch with just one activity (defined in manifest as main/defualt/launcher/home) and I see the same thing - it gets recreated if I press Home.


回答1:


Add android:launchMode="singleInstance" to your <activity> element in the manifest.




回答2:


Add

if (!isTaskRoot()) {
    finish();
    return;
}

to the onCreate() of your first Activity (see Android application restarts when opened by clicking the application icon).



来源:https://stackoverflow.com/questions/4548947/how-to-prevent-custom-home-launcher-app-restart-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!