-2

I am working on an Android app which requires a lot of resources, for this reason I decided to add an Exit button even though it is discouraged, the usual practice is to let the systems handle it via the Back Button. The issue is that it doesn't work, at least on the emulator. The app closes the main View, goes in the background and keeps logging. The first time I tried to exit by calling finish(), then I tried by calling super.onBackPressed(), then both of them, but the result is always the same.

override fun onCreateOptionsMenu(item: MenuItem): Boolean {
    when (item.itemId) {
        R.id.exti_item -> {
            finish()
            super.onBackPressed()
        }
    }
}

Is it possible to close and app? I could leave it to the OS, but apart from the memory usage I'm worried it could drain the battery.

FluidCode
  • 271
  • 2
  • 10
  • can you post the code where logging is done? – some user Feb 03 '20 at 21:53
  • That's irrelevant, it is a listener to the camera buffer in a sub frame, I prefer not deviate the discussion from the main point. – FluidCode Feb 03 '20 at 21:58
  • Does this answer your question? [How to force stop my android application programmatically?](https://stackoverflow.com/questions/5100728/how-to-force-stop-my-android-application-programmatically) – greeble31 Feb 04 '20 at 00:26
  • @Greeble31 Thanks, but the solution proposed there is probably too harsh. I call the methods to release the camera in onPause(), but I see that closing everything including the background threads is completed 4 or 5 seconds after onStop(). – FluidCode Feb 04 '20 at 00:34

1 Answers1

0

finish() only terminates your activity. You probably have services, or broadcast receivers, or ongoing tasks, or different active entities that are still running. You have to shutdown each component properly.

nsndvd
  • 800
  • 8
  • 21