0

I have used a Fragment to perform the background update of the app avoiding interruption if the activity is destroyed or paused.

Following this sample

the update task start in

if (mTaskFragment == null) {
      mTaskFragment = new TaskFragment();
      fm.beginTransaction().add(mTaskFragment, TAG_TASK_FRAGMENT).commit();
    }

and works fine.

My problem is that I want to allow the user to update the data using a Button updateButton but I haven't clear how could tell the TaskFragment to update again its task (e.g. the DummyTask in the linked sample).

Any suggestion?

AndreaF
  • 11,975
  • 27
  • 102
  • 168

1 Answers1

0

You could add a method to the TaskFragment to handle the data update, and when the button is clicked, simply trigger it

For example, add this method to the fragment

public void updateData(SomeParams ... params){
//do something
}

then in the activity for the given button add a click listener

and in it trigger mTaskFragment.updateData(zParams);

Lena Bru
  • 13,521
  • 11
  • 61
  • 126