4

In my app I'm implementing many finish() methods between activities. Should I be doing this? I think so because I'm helping conserve the user's battery. Is that true?

Also, Google apps don't implement an Exit button in their applications. but I see in many games they have an Exit button. Should apps implement an a exit button? Or perhaps for apps it's not necessary, but in videogames it is?

Jeff Atwood
  • 63,320
  • 48
  • 150
  • 153
Julio Del Valle
  • 381
  • 1
  • 4
  • 17

4 Answers4

2

Finishing an activity programmatically is absolutely OK. However, be aware that you shouldn't store a reference to the activity outside of it (if that's what you meant saying you finish activities between each other) because that creates a context leak. Every context leak will cost you about a megabyte of memory. Read more here: http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

Reg. the "Exit" button - actually, implementing it is a bad idea. Keeping some data in RAM takes much less power than creating that data by executing code in CPU. So it's preferred that once some data is created on the first launch it's then kept in memory rather than re-doing it every launch. This greatly saves the battery. That's why Android's lifecycle was designed in the way it is. By killing the app you clear the data from memory which means that on the next launch the CPU will consume some battery to re-create it. By allowing the "Exit" option you actually harm the users, not help them. And, by the way, properly implementing exit in the Android app is difficult, so it won't work anyway ;)

-- update: Renaud added a good point and I totally agree, see his post

Community
  • 1
  • 1
JBM
  • 2,930
  • 2
  • 24
  • 28
1

Imo it is not a good idea to finish an Activity unless the user requests or expects it but that is highly dependent on the particular application.

An exit button is not required if you rely on the back and home button. Nevertheless it may be convenient or even required if you want your game to run on any touchscreen not just Android.

mibollma
  • 14,959
  • 6
  • 52
  • 69
1

The decision to programmatically finish activities should be based on the desired navigation model for your application. Only finish activities if you don't want the user to be able to go back to it.

Finishing an activity to conserve resources isn't the right way to think about it. Instead you should design your activities to consume/free resources in the Activity lifecycle methods like onResume, onPause, onStart, onStop, etc.

On Android users typically use the back button to back out, or "exit" out, of a screen.

Ryan Reeves
  • 10,209
  • 3
  • 42
  • 26
1

I quote JBM:

Finishing an activity programatically is absolutely OK.

… but in nominal cases, that's not necessary and, moreover, could be the exact opposite of the android UI ergonomy. I suggest you to read carefully the dev guide: http://developer.android.com/guide/practices/ui_guidelines/activity_task_design.html

Esp. the Navigating Away from an Activity with BACK and HOME keys section.

On the Exit button implementation, I once more agree with JBM on the fact that implementing an Exit option will unfortunately lead to user's disappointment about the overall android ergonomy.

My point is that the doc, even if not perfect, provides a large and sufficient set of information on UI design, good practices, coding rules and optimization tips. It's to be read.

−− update: the popular angry birds application does not implement an exit option but rather use the back button and prompt the user for exit. It seems a really good approach.

Renaud
  • 8,783
  • 4
  • 32
  • 40