0

I am writing an android app that allows for the user to update some info to google drive with the google sheets API.

I have one activity that updates one spreadsheet, and another activity that updates a different spreadsheet.

I have an asynctask in each activity that is responsible for executing the updating code.

My issue is: I start the first activity - the user starts asynctask over there and simultaneously I also start the second activity, and over there the user starts the second asynctask - meaning I can't be sure which asynctask will finish first.

I want to report an error if one or two of the AsyncTasks fail.

My question is - How can I interact between two PostExecute Methods in different activities?

Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ofek Agmon
  • 5,040
  • 14
  • 57
  • 101
  • What kind of action do you want to take? What happends if the first asyncTask finishes with the activity killed? – droidpl Mar 09 '15 at 20:55
  • *How can I interact between two PostExecute Methods in different activities?* as method names said it "post" a message to UI thread ... there can be only one active Activity ... so ... answer yourself – Selvin Mar 09 '15 at 20:55

2 Answers2

0

One way to do that is using SharedPreferences to store and retrieve data in both AsyncTasks. this answer will guide you through SharedPreferences.

Another way would be to create a new BroadcastReceiver and notify it from the AsyncTasks. here's a good tutorial by vogella for creating receivers.

Community
  • 1
  • 1
Abdallah Alaraby
  • 2,222
  • 2
  • 18
  • 30
0

Start 2 IntentServices instead from your main activity. Make each service to report to the main activity when the service finishes its task.

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158