1

I'm new at Android Development...

I create a new activity and call finish(); method. But it still running, consuming battery, memory... Battery and memory consumption after activity is destroyed

Is there a way of stop the application completely, avoiding battery and memory consumption after activity is destroyed?

BrunoTS
  • 171
  • 2
  • 17
  • 2
    The system will reclaim the memory if it deems that necessary, it will otherwise keep the resources loaded because it's quicker in case the user comes back. It's also not really consuming anything. Free memory is wasted memory. Good use of memory is when there are relevant items still cached. Battery consumption is only caused by CPU activity, which won't happen unless you have a running thread that outlives an activity. Don't try to break that by killing your app process or by using "memory cleaner" apps. – zapl Oct 29 '18 at 20:42

2 Answers2

1

Duplicated Question!

You can't control when your app leaves the main memory, the OS does. Look closely at Activity.finish()

I think there will be no way of stopping the application completely, avoiding battery and memory consumption after the activity is destroyed.

Answer(Link) is : Activity.finish() called but activity stays loaded in memory

0

finish method just finish the intent! If you want to exit from app then use

system.exit(0);

Siamak Ferdos
  • 3,181
  • 5
  • 29
  • 56
  • This stop the profile windown on Android Studio... But my application still appearing on my battery and memory manager... – BrunoTS Oct 29 '18 at 20:30
  • Do you make any service in your app? – Siamak Ferdos Oct 29 '18 at 20:41
  • may be try this finishAffinity(); System.exit(0); – Nik Oct 29 '18 at 20:42
  • 1
    It is recommended not to use `System.exit(0);`, see for example [this SO post](https://stackoverflow.com/questions/32924802/why-one-should-not-use-system-exit0-in-android-application) – Bö macht Blau Oct 29 '18 at 20:46
  • ~Siamak Ferdos: There isn't any service on app. ~Nik: finishAffinity() requires `mimAppLevel` 16, and my is 15... ~ 0X0nosugar: `System.exit(0)` don't solve the problem, so I will remove it... – BrunoTS Oct 29 '18 at 20:52
  • Any chance other code getting executed after you issue `finish()`? [ `finish()` is non-immediate. I usually follow it with `return` ] – Bad Loser Oct 29 '18 at 21:10