I have app with multiple fragment.I running asynctask from fragment A and want stop it from fragment B How can I resolve this problem ?
Asked
Active
Viewed 139 times
0

Nam Nguyen
- 317
- 4
- 18
-
maybe it will help you http://stackoverflow.com/questions/3291490/common-class-for-asynctask-in-android – Linh Apr 21 '16 at 08:57
-
you can save the values from activity one and send to to second activity – Ameer Apr 21 '16 at 08:59
-
I try many way but not luck – Nam Nguyen Apr 21 '16 at 09:07
-
a good post on how to cancel an asynctask http://www.quicktips.in/correct-way-to-cancel-an-asynctask-in-android/ – Deepak Swami Jun 29 '16 at 17:19
1 Answers
2
I don't think you can use either use AsyncTask or AsyncTaskLoader for that. The easiest solution would probably be to do your download work in an IntentService, and communicate with it from the different activities.

urandom
- 1,147
- 2
- 12
- 21
-
My usage a a bit different, but here's my service: https://github.com/urandom/gearshift/blob/master/gearshift/src/main/java/org/sugr/gearshift/service/DataService.java#L84 and here's how i tell it what to do: https://github.com/urandom/gearshift/blob/master/gearshift/src/main/java/org/sugr/gearshift/service/DataServiceManager.java#L164 The broadcast receiver at the end of that file receives messages from the service In your case, the messages could be a list of progresses – urandom Apr 21 '16 at 09:08
-
-
But how IntentService send data back to activity to update listview item from activity A & activity B – Nam Nguyen Apr 21 '16 at 09:15
-
The services sends intents to anyone who wants to listen via: LocalBroadcastManager.getInstance(this).sendBroadcast(INTENT); any activity can then receive these events using a broadcast receiver: LocalBroadcastManager.getInstance(context).registerReceiver(RECEIVER); when you receive such an intent in activity A or B, you update your UI accordingly – urandom Apr 21 '16 at 10:05
-