0

Lets assume that Activity A is the parent Activity and Activity B is the child Activity. Activity B implements AsyncTask. After the AsyncTask finishes I want the user to be informed that the Async functionalty finished properly and then I want to my app to return to Activity A without the user interacting with Activity B. I know onPostExecute will facilitate what I am trying to do.

  1. Should i use snackbar or create a dialog?
  2. Is it possible after returning to Activity A to inform the user about the AsyncTask correct completion?

Maybe these questions are trivial but I am trying to get some more insight

Dhanumjay
  • 540
  • 7
  • 17
Giannis
  • 121
  • 2
  • 4
  • 13

3 Answers3

0

You can use interface to notify your activity for completion of asynctask. here is answer with example.

Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • I appreciate your answer. What i am trying to do is different. AsyncTask will be executed while child Activity is running. When AsyncTask it finishes i want the child Activty to close and the app return to parent Activty. – Giannis Jul 12 '17 at 11:23
0

Implement a snackbar in the onPostExecute method of your AsyncTask and also call finish() to end the activity. That should work.

Joshua
  • 589
  • 1
  • 5
  • 19
0
  1. You should use a dialog with setEnableToTochOutside(false) to prevent user interact with activity B on Preexcute of asynctask.
  2. On PostExcute, if you want return data or something like flag to activity A, From activity A, you startActivityForResult(A, B). And on PostExcute of activity B, you set Data and result before comeback to activity A. When activity A receive data, just make a notice here. Or if you want to notice on activity B, just make Toast, or a dialog with cancle button (finish activity B on press). About StartActivityForResult: an example here

Many kind to return data for activity A, you can research about LocalBroadcast or EventBus.