Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh fragments 'onResume?'

I want to refresh fragments from an Actvitiy. (Let's call the activity A) Activity A contains the fragments.

When I finish Activity B then Activity A should refresh the fragments.

I was thinking this would be done in onResume? I tried simply restarting the activity through an intent but that's not usability friendly.

So how do I refresh fragments when I resume an activity?

like image 945
user2883477 Avatar asked Dec 15 '13 18:12

user2883477


1 Answers

Just put this code inside

onResume()

For example you want to update your listview when u return to your fregment.

@Override
public void onResume() {
    super.onResume();
    if (allowRefresh)
    {
        allowRefresh = false;
        lst_applist = db.load_apps();
        getFragmentManager().beginTransaction().detach(this).attach(this).commit();
    }
}

Here getFragmentManager().beginTransaction().detach(this).attach(this).commit();

This line detach and re-attach the fragment so your content will be updated.

like image 70
Mehul Avatar answered Oct 10 '22 13:10

Mehul