0

I have the following situation:

One Main ListActivity. The list consists of POJO objects, each item is a different POJO.

Each POJO contains different groups. For each group I made different 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.

All group activities implement a custom class MyNavigationDrawerClass which is the core of the Navigation Drawer in my app.

Each ActivityA, B, C, etc, has a SettingsActivity which is strictly individual and depends on from where it has been started.

Now the question is: How to navigate from any A, B, C, etc, activity to the Main ListActivity every time the BackButton is pressed?

I will provide an example:

  1. App is started - Main List Activity is showed;
  2. Item is pressed and ActivityA with NavigationDrawer is started;
  3. The NavigationDrawer is opened and ActivityC is opened;
  4. When BackButton is pressed, the user is navigated back to ActivityA, but my desire is to navigate the user to the Main List Activity

What I tried:

  1. To put android:noHistory="true" for every ActivityA, ActivityB and ActivityC in the AndroidManifest. 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.
  2. To override onBackPressed in MyNavigationDrawerClass and start the Main List Activity using 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.

I hope I explained the situation clearly.

Any help will be appreciated.

taxo
  • 539
  • 1
  • 3
  • 21

1 Answers1

0

You can override the public void onBackPressed(){...} for redirect the user where you want like this :

public void onBackPressed()
{
    Intent intent = new Intent(this.getApplicationContext(), MainListActivity.class);
    startActivity(intent);    
} 

look at this link can help you

Community
  • 1
  • 1
Paul
  • 179
  • 1
  • 8