Differentiate between Android killing the app and user swiping it off on the recent apps list

后端 未结 7 2106
死守一世寂寞
死守一世寂寞 2020-12-29 10:50

I am working on a project, where while being on a specific Activity we show a local sticky notification. That should also be the case when the app is minimized. What I have

7条回答
  •  醉梦人生
    2020-12-29 11:23

    This is a comment I found in reddit that seems to me really interesting:

    Swiping an app away will effectively "kill" most apps. You can test this out using ADB if you have the SDK installed. Swipe everything out of your recents list, then launch the browser.

    Use ADB to run 'ps' on the device and verify that the com.google.android.browser process is running. Go to the home screen, it's still running. Launch some other apps, and the com.google.android.browser process is still there.

    Swipe it out of the recents list, however, and the process is gone. You can create a test app to further verify, and log the onDestroy() call in your Activity. It's not called when you back or home out of the app, or when you launch other apps. It does get called when you swipe the app out of the recents list though. I do agree that the recent apps list isn't really "multitasking".

    The apps in the list aren't necessarily even running, the processes could have been killed by the memory manager long before you try to re-open it. However, you can't argue that the only purpose is to jump quickly to other apps when the swiping makes the actual process go away.

    This is another good answer about what happen when you swipe an app out of the recent apps list. But the part that I liked most was:

    Actually, removing an entry in recent tasks will kill any background processes that exist for the process. It won't directly causes services to stop, however there is an API for them to find out the task was removed to decide if they want this to mean they should stop. This is so that removing say the recent task of an e-mail app won't cause it to stop checking for e-mail.

    If you really want to completely stop an app, you can long press on recent tasks to go to app info, and hit force stop there. For stop is a complete kill of the app -- all processes are killed, all services stopped, all notifications removed, all alarms removed, etc. The app is not allowed to launch again until explicitly requested.

提交回复
热议问题