android - Pro and cons calling finish -


i want know pro , cons when try open new activity android , destroy previous 1 straight away calling finish.

people think bad idea because android can take care of activity , drop them when there memory used, if inside activity once , user never come back? bad option?

also finishing activity, history button "clear", wont activity ( if user flow needed go think should not call finish ).

and in terms of memory, better kill activity finish or leave android have activity in background who knows how long time?

i feel like, kind of system gc activity closed , make sure user wont need tap button 100 times before getting out of application.

so think? better call finish or not

i want know pro , cons when try open new activity android , destroy previous 1 straight away calling finish.

either want user return previous activity via button, or not.

  • if want user return previous activity via back, not call finish()

  • if not want user return previous activity via back, there multitude of options, depending upon do want user go when user presses back

people think bad idea because android can take care of activity , drop them when there memory used

no, android not this.

is better kill activity finish or leave android have activity in background knows how long time?

it "better" have activity implement ontrimmemory() , reduce memory footprint needed. not harm user expectations of button.

that kind of system gc activity closed , make sure user wont need tap button 100 times before getting out of application

few users "tap button 100 times". press home, or bring overview screen (a.k.a., recent-tasks list), or navigate app other means.

now, being said, there will times when want clear task (back stack), again eye towards providing logical flow user. example, in email app:

  • the user launches app, , fresh task created, user going app's launcher activity, shows messages in user's inbox (a)

  • the user taps on "search" action bar item, bringing search activity, can search various criteria (b)

  • the user fills in search criteria , clicks "go!" button, search , shows matching email messages (c)

  • the user taps on email message, bringing email-viewing activity (d)

  • the user taps "delete" action bar item, should delete message , return user... somewhere

if believe user should return search results (c), call finish() in d. if, however, believe user should return inbox (a), call startactivity() on appropriate flags (e.g., intent.flag_activity_clear_task), clear out stack , return user a.

in sum: not call finish() deal heap space; implement ontrimmemory() instead. however, if navigation calls finish(), use it.