1

A have ActivityA-->ActivityB-->ActivityC. If user push HomeButton while he is at ActivityB, and then he wants to re-open application i want to restart activity ActivityA. Well thats working calling onStop(); and finish(); in ActivityB.

But when user goes from ActivityB to ActivityC and then wants to return to ActivityB, ActivityB has already called finish(); so user will appear at ActivityA.

So how to make ActivityB available if returning from ActivityC and also finish it if user use HomeButton ?

AndroidLearner
  • 4,500
  • 4
  • 31
  • 62
kort.es
  • 479
  • 2
  • 7
  • 26
  • When a user presses "HomeButton" it means that they want to return to that Activity later, that is the Android's behavior. You cannot override the "HomeButton" as far as I know. – Carnal Dec 13 '12 at 12:55
  • Don't try to solve this by mucking around with the lifecycle methods. Android provides a mechanism to do exactly what you want. See my answer. – David Wasser Dec 13 '12 at 13:01
  • dont call `finish()` button when moving from `B to C activity` – Rahul Baradia Dec 13 '12 at 13:09
  • http://stackoverflow.com/questions/8515936/android-activity-life-cycle-what-are-all-these-methods-for – Yaqub Ahmad Dec 20 '12 at 18:12

3 Answers3

4

Just set

android:clearTaskOnLaunch="true"

on your root activity (the one used by the launcher to start your application) in the manifest. Then, when the user is using your application, as soon as he presses the HOME key, your task will be stripped back to the root (starting) activity.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • +1, just in time). The best answer for me, but seems the question is a little bit different) – Daler Dec 13 '12 at 13:08
0

when your going from Activity B to Activity C don't call finish() on Activity B.

I think your doing like this

 startActivity(new Intent(Activity_B.this,Activity_C.class));
 finish();

Remove finish() when moving from Activity B to Activity C.

Go to this stackoverflow question for more details you ll get it.

Community
  • 1
  • 1
Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121
0

Don't call method finish() in ActivityB

Take a look here and here

Never call onStop() by yourself. These methods are lifecycle methods and called by the android system.

endian
  • 4,761
  • 7
  • 32
  • 54