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

后端 未结 7 2107
死守一世寂寞
死守一世寂寞 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:16

    when swiping app to left if any Thread still run in your app Interrupted but service not stopped, when you kill handy app Thread and services are stopped.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-29 11:27

    the behavior is similar to but not exactly the same as closing an app -- in general (for apps that don't define explicit back button handling) it's the same thing as hitting back enough times from within an application that you exit out of it.check out this link discussion it has some good input on the subject

    0 讨论(0)
  • 2020-12-29 11:30

    First, let's get one thing clear: Android MAY NOT CALL onDestroy(). Referring to the Activity Page, from Honeycomb onward, onPause() and onStop() are guaranteed to be called before an app is killed.

    Be aware that these semantics will change slightly between applications targeting platforms starting with HONEYCOMB vs. those targeting prior platforms. Starting with Honeycomb, an application is not in the killable state until its onStop() has returned. This impacts when onSaveInstanceState(Bundle) may be called (it may be safely called after onPause() and allows and application to safely wait until onStop() to save persistent state.

    So after (hopefully) clearing the air on the Android lifecycle, I think you can achieve what you want by putting the notification removing code in onStop() instead. If you end up needing it back because the user actually DOES come back to the specific Actvitiy(IE not killed), you can bring it back in onRestart().

    0 讨论(0)
  • 2020-12-29 11:33

    You can check for when the user swipe-closes the app by adding a service to your app, and implementing the onTaskRemoved method: https://stackoverflow.com/a/26882533/2441655

    0 讨论(0)
  • 2020-12-29 11:33

    By Swiping from recent task list removes only from recent tasks .. It was also called onDestroy before android 5.0 . Might be you are having issue above api level 20 devices. System kill normally can not be executed in normal android activity lifecycle. It just finishes the activity on back press event.

    0 讨论(0)
提交回复
热议问题