简体   繁体   中英

back button issue in Android app

I own a mobile android app on google playstore "Geology of India". However, I am not able to switch to the main screen on back press event. Currently, this app has exit option instead.

I have the following screens:

1) Splash screen 2) Main category screen which connects to PHP Json to get all categories. 3) If I click on any of the category button, then it goes to the content page, which displays images and text combination.

Now, if I click on back button of android device, then it will ask you to exit the app. How do I move back from third screen to second / parent screen?

I have tried various methods, but it simply exits the main app or terminates.

enter image description here

You seem to be overriding onBackPressed() .

You don't need to override onBackPressed() in order to start the previous activity. the default implementation finish() es the current activity and the previous activity in the stack is shown automatically.

Also make sure you are starting the Content activity from your Main activity without any flags, and that you are not calling finish() in your main activity after starting your Content activity. What you want to do is just default behavior and you don't need to dig into anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM