I have made a simple app on Android which increases the counter value by one and goes to next activity. At this point, if i press the back button, instead of just leaving the app or going to homescreen of the app, it goes to previous screen and reduces the counter by one. How do i prevent this from happening and keep the counter value same. Thanks
Asked
Active
Viewed 135 times
-1
-
1create a static counter ! – Tushar Pandey Jun 13 '13 at 11:28
3 Answers
1
use like that
@Override
public void onBackPressed() {
super.onBackPressed();
counter--;
// fireintent here or finish() call
}

Sunil Kumar
- 7,086
- 4
- 32
- 50
0
You could intercept the back click and handle it differently:
@Override
public void onBackPressed() {
// do something else.
}

Warpzit
- 27,966
- 19
- 103
- 155
0
When starting your new intent make sure you include NOHISTORY to prevent the activities piling up on the stack. You will need to save the value into your applications shared prefrences or another file to ensure that the value will be kept when your application exits.

chefburns
- 407
- 3
- 12