1

I want to update the data on my android fragment when it's loaded on top of the stack or when the application is resumed or on some button click event. I tried using attach and detach method but its not working. I also tried onbackstackchangedlistener() but no success. Any help would be appreciated.

rebatoma
  • 734
  • 1
  • 17
  • 32
ROHIT W
  • 36
  • 1
  • 8

2 Answers2

0

As he answered here

The fragments onResume() or onPause() will be called only when the Activities onResume() or onPause() is called. They are tightly coupled to the Activity.

Read the Handling the Fragment Lifecycle section of this article.

Community
  • 1
  • 1
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
0

If you are able to get the onResume working as Shylendra answers here is how one could handle it.

Just put this code inside

onResume()

Here is an example for when you want to update your listview when you return to your fragment.

@Override
public void onResume() {
    super.onResume();
    if (allowRefresh)
    {
        allowRefresh = false;
        myListView = db.load_apps();
        getFragmentManager().beginTransaction().detach(this).attach(this).commit();
    }
}
C. Skjerdal
  • 2,750
  • 3
  • 25
  • 50