简体   繁体   English

Android应用程序中的后退按钮问题

[英]back button issue in Android app

I own a mobile android app on google playstore "Geology of India". 我在Google Play商店“印度地质”中拥有一个移动Android应用。 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. 1)初始屏幕2)主类别屏幕,它连接到PHP Json以获取所有类别。 3) If I click on any of the category button, then it goes to the content page, which displays images and text combination. 3)如果单击任何类别按钮,则它会转到内容页面,该页面显示图像和文本组合。

Now, if I click on back button of android device, then it will ask you to exit the app. 现在,如果我单击android设备的后退按钮,那么它将要求您退出该应用程序。 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() . 您似乎在重写onBackPressed()

You don't need to override onBackPressed() in order to start the previous activity. 您无需重写onBackPressed()即可启动上一个活动。 the default implementation finish() es the current activity and the previous activity in the stack is shown automatically. 默认实现finish()是当前活动,并且堆栈中的上一个活动会自动显示。

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. 此外,还要确保从Main活动中启动Content活动且没有任何标志,并且确保在启动Content活动后没有在main活动中调用finish() What you want to do is just default behavior and you don't need to dig into anything. 您想要做的只是默认行为,而无需深入研究。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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