0

I have a fragment and there is a list of items.I have an async task in the fragments oncreateview which loads the items. Upon the click of items I am launching an activity. After I perform some action in the activity, the activity will close and I need to reload the fragment list items via async call. How to reload the list on close of activity in the fragment?

5 Answers5

0

The items activity will automatically go into the Back-stack and when the activity above that gets completed then the previous ITEMS activity will come into picture automatically.

dev
  • 83
  • 9
0

You don't need to reload the list actually.

Override onSaveInstanceState of your Fragment and save the list at this moment. Then in onCreate get the content of your list (that your saved in the Bundle) and give it to your adapter. Job done.

Now you are probably wondering how to save your items. You can save them into the Bundle directly. Or in a SQLite database.

Community
  • 1
  • 1
Gordak
  • 2,060
  • 22
  • 32
0

The easiest way to do it is to launch your activity using startActivityForResult(Intent intent, int requestCode, Bundle options). Then overide the onActivityResult(int requestCode, int resultCode, Intent data) method to refresh your datas. This method will be call after the activity launch with startActivityForResult(Intent intent, int requestCode, Bundle options) terminate.

sonic
  • 1,894
  • 1
  • 18
  • 22
0

you can use onResume() method in fragment. just call your Async task from OnResume method.

0

Seems like a good job for Loaders and Cursors, it will do all this for you . You might consider implementing LoaderManager.LoaderCallbacks in your Fragment or Activity .

Read on AsyncTasks vs Loaders . I hope that helps

Otieno Rowland
  • 2,182
  • 1
  • 26
  • 34