11

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.

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!

Pawel
  • 407
  • 1
  • 6
  • 14
twig
  • 4,034
  • 5
  • 37
  • 47
  • Read about the activity lifecycle. And understand this http://www.androidjavadoc.com/1.0_r1_src/android/app/doc-files/activity_lifecycle.png – Kiril Kirilov Jan 04 '11 at 15:08
  • Hi Fiction, I've read the documentation many times and the image you posted was where I got my understanding from. I was just confused to see that it was resuming rather than restarting after I called Activity.finish(). – twig Jan 06 '11 at 04:25

1 Answers1

21

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.

Andrew White
  • 52,720
  • 19
  • 113
  • 137
  • 3
    Thanks for that Andrew, that was a bit of a mind opener. I've always been thinking that Activity.finish() closes it rather than puts it on the queue for closure. Gotta do some rework in that case. – twig Jan 06 '11 at 04:28