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
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.