Reputation: 5
I am developing a mobile app for android, with eclipse as my platform. Whenever I use the back button of the mobile using the emulator, the app closes. I want to just go back to the previous page, but it exits the app. How can I do it? I really hope you could me with this. Thanks in advance!
Upvotes: 0
Views: 356
Reputation: 34823
Two chance for this
1) You may use viewflipper for displaying different pages, So you have only one activity. If so u need to override onKeyDown function and set your view flipper display child as you want when the keycode is KeyEvent.KEYCODE_BACK
2) If you are using different activities (Which is always preferred ) you may be finishing the old activity while calling new one. Then remove that code for finishing, finish()
Upvotes: 1
Reputation: 6245
Before u start a new Activity, you should not call finish () on the current Activity If Finish () is not called and you move to a new activity, and press BACK then you will be taken to the previous activity...
learn about the activity lifecycle, and you will understand http://stuffthathappens.com/blog/2008/11/05/android-activity-lifecycle-updated/ http://www.anddev.org/lifecycle_of_an_activity-t81.html
Upvotes: 0
Reputation: 57672
I guess you start a new activity and call finish()
on the old one, right!? Don't do that, just start the new activity.
If that's not the case, please provide the code where you start your new activity.
Upvotes: 2