Reload activity in Android
Is it a good practice to reload an Activity
in Android?
What would be the best way to do it? this.finish
and then this.startActivity
with the activity Intent
?
You can Simply use
finish();
startActivity(getIntent());
to refresh an Activity
from within itself.
for those who don't want to see that blink after recreate() method simply use
finish();
overridePendingTransition(0, 0);
startActivity(getIntent());
overridePendingTransition(0, 0);
This is what I do to reload the activity after changing returning from a preference change.
@Override
protected void onResume() {
super.onResume();
this.onCreate(null);
}
This essentially causes the activity to redraw itself.
Updated: A better way to do this is to call the recreate()
method. This will cause the activity to be recreated.
simply use
this.recreate();
this will trigger the onCreate method in the activity