Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Message From Thread Created by Activity A to Activity B

I currently have a thread/AsyncTask that I start in Activity A. Before that AsyncTask is started though, Activity A makes an object which takes in Activity A's Context so it can instantiate a NotificationCompat.Builder. The object uses this builder to make/show a notification.

This object is then passed to the AsyncTask as the AsyncTask is created and started. This allows the AsyncTask to update the object (and the notification) with its progress.

Once the AsyncTask has been started though, Activity A calls finish(), and the activity that started it, Activity B, resumes. What I would now like to happen is to have the object send/attempt to send a message to Activity B once the AsyncTask has said it is 100% complete. How can I achieve this?

PS: let me know if a picture would make the scenario more clear.

like image 942
rolledback Avatar asked Dec 20 '25 22:12

rolledback


1 Answers

As far as I have understood your question Activity A is started from Activity B. You can start A from B via startActivityForResult then rather finishing A when AsyncTask starts you finish() A when 100% task is loaded by AsyncTask and send result to A. You can implement callback interface to send result to Activity A from AsyncTask. Now call finish() to Activity A with setResult() and pass the result in intent to Activity B.

like image 124
Haris Aftab Avatar answered Dec 23 '25 14:12

Haris Aftab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!