Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload activity in Android

People also ask

How do you reload activity?

In some situations, we need to recall activity again from onCreate(). This example demonstrates how to reload activity in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

What does finish () do in Android?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.


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