Android app with 2 activities - different actions on key code back?

Go To StackoverFlow.com

0

I have a problem on an Android app.

I have 2 activities : Activity1 and Activity2.

Activity1 is my default activity. Activity2 is a second activity.

Here is the code in Activity1 for the onKeyDown with KEYCODE_BACK :

finish();
return true;

Here is the code of my Activity2 for the same event :

Intent myIntent = new Intent(this, Activity1.class);
startActivityForResult(myIntent, 0);
return true;    

My problem is : - I start the app, I press "Back" : application is closed - OK - I start the app, I go to Activity2 (through a button), I press "Back" : I'm back to Activity1, I press again "Back" : I'm back to Activity2 instead of applying "finish()".

Can somebody tell me what I'm doing wrong?

For information, my Activity2 is called like this:

Intent myIntent = new Intent(this, Activity2.class);
startActivityForResult(myIntent, 0);
return true;

Thanks in advance.

Romain

2012-04-05 16:48
by Romain


0

The application is exactly behaving according to your code. Nothing is wrong. The question is what do you expect on how you want your application(activities) to behave. Another thing is that don't override back button. Android user know how back button behave and they want it to behave consistently across applications and if yours behave differently, they will be pissed.

2012-04-05 16:55
by Win Myo Htet
You are right it's working well without overriding the back button. Thx - Romain 2012-04-05 17:01
Ads