[英]Proper navigation between activities using navigation drawer and back button?
I have the following situation: 我有以下情况:
One Main ListActivity
. 一个主要的
ListActivity
。 The list consists of POJO objects, each item is a different POJO. 该列表由POJO对象组成,每个项目都是一个不同的POJO。
Each POJO contains different groups. 每个POJO包含不同的组。 For each group I made different
Activity
. 对于每个小组,我进行了不同的
Activity
。
Lets say POJO1 contains groups A , B and C , when pressed, ActivityA will be opened and the navigation between the rest activities ActivityB and ActivityC is done using NavigationDrawer
. 比方说POJO1包含组A,B和C,按下时,ActivityA将被打开,其余活动ActivityB和ActivityC之间的导航使用进行
NavigationDrawer
。
All group activities implement a custom class MyNavigationDrawerClass which is the core of the Navigation Drawer
in my app. 所有小组活动都实现一个自定义类MyNavigationDrawerClass ,这是我应用程序中
Navigation Drawer
的核心。
Each ActivityA , B , C , etc, has a SettingsActivity which is strictly individual and depends on from where it has been started. 每个ActivityA , B , C等都有一个SettingsActivity ,它严格独立,并取决于从何处开始。
Now the question is: How to navigate from any A , B , C , etc, activity to the Main ListActivity every time the BackButton
is pressed? 现在的问题是:每次按下
BackButton
时,如何从任何A , B , C等活动导航到Main ListActivity?
I will provide an example: 我将提供一个示例:
NavigationDrawer
is started; NavigationDrawer
ActivityA ; NavigationDrawer
is opened and ActivityC is opened; NavigationDrawer
并打开ActivityC ; BackButton
is pressed, the user is navigated back to ActivityA , but my desire is to navigate the user to the Main List Activity BackButton
,用户被导航回到ActivityA ,但是我的愿望是将用户导航到Main List Activity What I tried: 我试过的
android:noHistory="true"
for every ActivityA , ActivityB and ActivityC in the AndroidManifest
. AndroidManifest
中的每个ActivityA , ActivityB和ActivityC放置android:noHistory="true"
。 That did not work because when I open the SettingsActivity for example from ActivityA and return, the user in navigated to the Main List Activity , and not to the ActivityA - it's confusing and misleading. onBackPressed
in MyNavigationDrawerClass and start the Main List Activity using Intent
. onBackPressed
中的onBackPressed并使用Intent
启动主列表活动 。 That did not work either because there are still previous activities in the stack and when the BackButton
is pressed from Main List Activity , the user is navigated to them. BackButton
时,用户被导航到了这些活动。 I hope I explained the situation clearly. 我希望我能清楚地说明情况。
Any help will be appreciated. 任何帮助将不胜感激。
You can override the public void onBackPressed(){...}
for redirect the user where you want like this : 您可以覆盖
public void onBackPressed(){...}
以便将用户重定向到所需的位置,如下所示:
public void onBackPressed()
{
Intent intent = new Intent(this.getApplicationContext(), MainListActivity.class);
startActivity(intent);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.