Activity.finish() called but activity stays loaded in memory

When I run my app on the debugger, I get the main thread and 3 binder threads.

On a button click I call Activity.finish(), which looks like it ends the activity as the UI closes and goes back to the home screen.

  • How to avoid automatically appear android keyboard when activity start
  • Change background popupMenu in Android
  • WebView hides soft keyboard during loadUrl(), which means a keyboard cannot stay open while calling javascript
  • Add item to ListView without reloading
  • Drawable image on a canvas
  • How to integrate PayU money Gateway in Android?
  • However, in the debugger, it still shows the main thread and 3 binder threads as “(running)“.

    I am baffled to why this is happening. Even more so, it is causing my app to call Activity.onResume() when I run it again after exiting the app.

    I currently override these methods in the Activity, but I call the appropriate super functions in each one:

    • onDestroy()
    • onPause()
    • onResume()
    • onSaveInstanceState()

    Any help or advice regarding this is much appreciated!

  • Is there any way to control views inside NavigationView header?
  • Android Studio: Gradle Refresh Failed - Could not find com.android.tools.build:gradle:2.2.0-alpha6
  • How to get a list of backstack fragment entries in android?
  • WebView and HTML5 <video>
  • Android: Implicit Intents vs. Broadcast Receivers
  • Turning a string into a Uri… (Android)
  • One Solution collect form web for “Activity.finish() called but activity stays loaded in memory”

    You don’t control when your app leaves main memory, the OS does. Look closely at Activity.finish…

    Call this when your activity is done
    and should be closed. The
    ActivityResult is propagated back to
    whoever launched you via
    onActivityResult().

    Note that is says nothing about memory. As to calling Activity.onResume, that’s exactly what you would expect for the lifecycle; remeber that onResume is not just called after a resume but even when the app is first launched after onCreate.

    While not exactly what you asked I suggest you read this article about exit buttons which goes on to say something very important

    [Activity.finish] is exactly equivalent to hitting the back button.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.