Normally, when user click the back button in android, the next view is not refreshed. I had this problem when I was doing the settings. if user changed the some settings and hit back button, the new settings won’t be applied to the “back” list view since all the cells are reused.
you can do some scroll to refresh the list view but that is definitely not something we wanna user to do.
first solution is to override the onResume method in the back view, but it is not guaranteed to work in listView.
However the following code should do the work:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && isNightModeToggled) {
Intent a = new Intent(this,MainActivity.class);
a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(a);
return true;
}
return super.onKeyDown(keyCode, event);
}
Happy Coding!!!!
0 comments:
Post a Comment