views:

331

answers:

3

Android - Can I force BACK button to go 2 steps back in the Acitivty stack with some kind of code? I know I can override the onKeyDown method but I want BACK to do it's thing, just twice!

A: 

I am thinking of it this way:

A -> B -> C

A,B,C activities.

You can't do a back twice since the first onKeyDown will be executed in C and the second one should be executed in B.

I don't know why you are trying to do, but here are some options.

a) Using the android:noHistory tag:

Perhaps your C activity is doing something that doesn't need a view and that's why you want to back twice.

b) Using an intent. Something like:

Intent intent = new Intent(C.this, A.class);
startActivity(intent);

c) Using the [finishActivityFromChild() method][2]. I have never try it, but it looks like you can use it to decide what to do on B depending of how C ended.

[2]: http://developer.android.com/intl/zh-TW/reference/android/app/Activity.html#finishActivityFromChild(android.app.Activity, int)

Macarse
A: 

There's an Android Devlopers blog about using the back key here - http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html

Just set it up to go back to whichever activity you want

Donal Rafferty
A: 

please refer the link below for clearing intent from stack trace with the use of flags.

http://stackoverflow.com/questions/3750776/android-how-can-i-initialise-state-in-one-activity-then-have-another-refresh-th/3751190#3751190

MGS