0

I have one activity which I start with different parameters. I set parameters with intent help. Each parameter have own separate action.

This activity has GridView with content which depends from income parameters.

First start:

Intent intent = new Intent(this, ArticlesListActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);

Second start:

startActivity(new Intent(ArticlesListActivity.this, ArticlesListActivity.class));

Third start:

Intent intent = new Intent(this, ArticlesListActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);

I need to start this Activity with first parameters, then with other parameters and then again with first parameters. And when I make third launch I need this will be single Activity of Application. Are there a way to do this?

Val
  • 4,225
  • 8
  • 36
  • 55
  • Please explain your problem better. Why are you launching the same activity 3 times? Is the activity launched from the same activity, or from different activities? How does the user get back from `ArticlesListActivity`? Your question isn't clear enough. – David Wasser Dec 18 '13 at 14:11

4 Answers4

0

An activity has a life cycle and in order to start the activity with different parameters while the same activity is running is to load the activity again from the current instance of the articleslistactivity but have in mind dat starting d activity again nd again will only stop the current instance nd you will have three instances in stack.

Tega
  • 47
  • 6
0

I think this link you have to helpful for remove all activity in Top of The Stack

Check this link

Clear all activities in a task?

Put this code in Your Class

Intent intent = new Intent(this,destinationactivity.class); intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP | FLAG_ACTIVITY_CLEAR_TASK | FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Community
  • 1
  • 1
Sanket990
  • 665
  • 1
  • 10
  • 22
0

Try

Intent intent = new Intent(this, main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
JackTools.Net
  • 734
  • 6
  • 13
0

Whenever you wish to exit all open activities, you should press a button which loads the first Activity that runs when your application starts then clear all the other activities, then have the last remaining activity finish. to do so apply the following code in ur project

Intent intent = new Intent(getApplicationContext(), FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);

The above code finishes all the activities except for FirstActivity. Then we need to finish the FirstActivity's Enter the below code in Firstactivity's oncreate

if (getIntent().getBooleanExtra("EXIT", false)) {
    finish();
}
The Ray of Hope
  • 738
  • 1
  • 6
  • 16