1

I have a database tree structure in the backend of my application. It basically looks like the following:

List
  |- View

I wrote the functionality to transform a View to a List displaying the View. Shown in here:

List
  |- List
     |- View

When triggering the toList() function the Application should rebuild the structure in the database, and switch to the new List Activity displaying the list content.

All of the above works, except one thing:

When switching to the new List Activity the previous View should be removed from the stack in order to keep the order when pressing the 'back' button.

I tried with the following intent:

Intent i = new Intent(ViewActivity.this, ListActivity.class);
// new_item is a DTO containing the needed id to create the List activity
i.putExtra("selected_item", _new_item);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PostActivity.this.startActivity(i);

as well as:

Intent i = new Intent(ViewActivity.this, ListActivity.class);
// new_item is a DTO containing the needed id to create the List activity
i.putExtra("selected_item", _new_item);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
PostActivity.this.startActivity(i);

which both didn't work as expected.

Is there any other method of maybe using finish() with the above intent? I explicitely don't want to start the activity for a result.

hGen
  • 2,235
  • 6
  • 23
  • 43

1 Answers1

1

Just add a finish() at end of your code and remove the flags, this will destroy the ViewActivity and it will be removed from your stack!

Intent i = new Intent(ViewActivity.this, ListActivity.class);
// new_item is a DTO containing the needed id to create the List activity
i.putExtra("selected_item", _new_item);
PostActivity.this.startActivity(i);

finish();
Lucas Ferraz
  • 4,112
  • 2
  • 18
  • 23