Reputation: 169
I am try to add theme change option in my application.I have a main activity called timeline.And from there user can go to themechange activity can change theme.It changes the theme of the themechange activity but not the timeline i.e mainactivity.When i reload the timeline activity again i can see the chnage.
Then i add the following code to save button in themechange activity to reload timeline activity
save.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
Intent i = new Intent(BackgroundChange.this, TimeLine.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
Intent k = new Intent(BackgroundChange.this,
SettingsActivity.class);
startActivity(k);
}
});
and it works well.
But when i exit my application and start again i can see the timeline acivity which was before themechage.
i use following code for exit application
exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
});
and if i exit again i can see the changed timeline.I want to clear all acitivites when exit my application.I can not retain any previous activity after exit. Now what can i do?Please give me a suggestion..
Upvotes: 0
Views: 2214
Reputation: 6899
However if you use this.finish() it works.Remove all the intent and just use "this.finish()". Surely it will work. if it's not working, then use System.exit(0) after finish().
Upvotes: 0
Reputation: 495
In the exit,
exit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(),TimeLine.class); //This will finish all activities except TimeLine
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("exit", true);
startActivity(intent);
}
});
In timeline's OnCreate,
if(getIntent().getBooleanExtra("exit", false))
finish(); //This will finish your main activity
Upvotes: 2