I have several activity including TimeLine Activity. This activity start when user logged in successfully to my application. However I have a menu for theme change of my application. When I go to change application theme i does not finish Timeline activity because of next time use. I change my theme color and background and save changes go to Timeline activity with new theme. Then when I exit my application using following code
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// Ask the user if they want to quit
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("")
.setMessage("Do you want to exit")
.setNegativeButton("No", null)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
// @Override
public void onClick(DialogInterface dialog,
int which) {
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_CLEAR_TASK);
startActivity(intent);
}
}).show();
return true;
}
return super.onKeyDown(keyCode, event);
}
But when I start my application again I see the Timeline Activity which was before the theme change. I think Timetine activity instance retain in stack although i start new Timeline activity from ThemeChange Activity.
Activity Flow
Timeline(With Theme Black) --> ThemeChange(By pressing ThemechangeMenu) --> Change Theme and Save Button click --> Start Again TimeLine(With New Theme Successfully) --> Exit my Application Using Avobe code --> Start again my Application --> Appears TimeLine(with Balck Theme not the changed theme)
How can I destroy the previous instance of TimeLine from stack when new Timeline instance is running from Themechange activity using save button click listener?
place finish();
after startActivity(intent);
in your code and add android:lauchMode="standard"
for the TimeLineActivity in the manifest
file. Then the activity
will not be in stack.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.