kort.es
kort.es

Reputation: 479

android activity life cycle

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 ?

Upvotes: 1

Views: 156

Answers (3)

Rahul Baradia
Rahul Baradia

Reputation: 11961

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.

Upvotes: 0

David Wasser
David Wasser

Reputation: 95646

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.

Upvotes: 4

endian
endian

Reputation: 4879

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.

Upvotes: 0

Related Questions