How to Refresh the Fragment After Activity Finished in Android

How to refresh the fragment after activity finished in android?

For solving it you can start register Activity like below :

Intent intent = new Intent(getActivity(), register .class);
startActivityForResult(intent, 10001);

And when you finish your activity you should setResult like below :


Now in your fragment you will get event of finishing your activity by overriding onActivityResult() in the fragment.

public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
if ((requestCode == 10001) && (resultCode == Activity.RESULT_OK))
// recreate your fragment here
FragmentTransaction ft = getFragmentManager().beginTransaction();

That's it.

Hope it will help you.

How can I refresh a fragment after coming back from an activity?

One way to solve this is to use startActivityForResult(intent, MyStatusCode) and then capture the return by using something like:

protected void onActivityResult(int requestCode, int resultCode, Intent data)
if (requestCode == MyStatusCode) {
//Refresh the fragment here

Reload fragment when activity finish

override onResume in your fragment and notify your adapter

protected void onResume() {

when you will go to another activity onPause of the fragment will call and when coming back onResume() will call.So you can notify about data changes in the listview to the adapter

Android Studio refresh the activity and display the current fragment

Instead of start new with same Activity you should call recreate and inside onCreate method you have to check savedInstanceState == null before init default fragment

public boolean onOptionsItemSelected(@NonNull MenuItem item) {
Configuration configuration = new Configuration();
Intent intent = new Intent();
switch (item.getItemId()){
Locale localePl = new Locale("pl");
configuration.locale = localePl;

Locale localeEn = new Locale("en");
configuration.locale = localeEn;

return true;
    override fun onCreate(savedInstanceState: Bundle?) {
if (savedInstanceState == null) {
// init default fragment

How to refresh previous fragment after closing an activity who was started inside an Adapter?

In the activity of your fragment you can do something like this:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
requestCode &= 0xffff;
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (fragment != null) {
fragment.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);

Or you can use a Event bus like:

Refresh Fragment at reload

I think you want to refresh the fragment contents upon db update

If so, detach the fragment and reattach it

// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

Your_Fragment_TAG is the name you gave your fragment when you created it

This code is for support library.

If you're not supporting older devices, just use getFragmentManager instead of getSupportFragmentManager


This method requires the Fragment to have a tag.

In case you don't have it, then @Hammer's method is what you need.

refresh fragment after changing data in database

I think you are having this issue because of the below code in your MainActivity:

FragmentOne fragmentOne = new FragmentOne();
fragmentOne.getFragmentManager().beginTransaction().replace(, fragmentOne).commit();

You try to get the instance of the fragment manager with getFragmentManager() who call Activity.getFragmentManager but your fragmentOne isn't attach to the activity so the method return null and you get a java.lang.NullPointerException

Instead of fragmentOne.getFragmentManager() use getSupportFragmentManager() directly from the activity.

Hope this helps.

Refresh Fragment From Activity After Updating Data on SQLite Xamarin Android

In you Fragment, you can override the OnResume method. If you back to the fragment from Acitivty. you should query the new data from DB, then set the new value to the controls in Fragment.

 public override void OnResume()
PHName.Text = photoDAO.GetFirstPhotos(Id).PhotoName;

Here is running GIF.

Sample Image

You can see this lifecycle about Fragment. Every time you display the Fragment,OnResume method will be executed. You get the newest data from DB, then set it to the Fragment page.
Sample Image

Here is my demo.

Related Topics

Leave a reply