Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I update the UI of an activity which is in background?

The question is more conceptual than coding-related.

I have an app with Activity A and B.

I call an AsyncTask from Activity A, while the call is being made, I don't want to block the user showing the progressdialog, so my user can freely move around the application without getting bored of waiting.

Now, the query is AsyncTask or lets say a Service is being called from Activity A which is responsible for downloading some kind of data from the server. While the call is being made, the user has changed the Activity and Activity A has gone to background.

Now, while the user is freely moving around the application, he just wants to come back to Activity A to check the download status,(which is something lets say I set some data to my TextView).

Now the question is, once the download is over , while my Activity A is still in background, my UI should be updated while Activity is still in background. This way the user feels he gets the data before he switches to Activity A.

Is this possible, if so how? Summarizing my question, can I update the UI of an Activity while it is still in background with the Asynctask or Service which the Activity invoked to fetch data from server.

One post suggested that ideally I need to update the **UI in onResume(). My question is, is this the only approach?

like image 790
akash89 Avatar asked May 27 '15 16:05

akash89


1 Answers

once the download is over , while my Activity A is still in background, my UI should be updated while Activity is still in background. This way the user feels he gets the data before he switches to Activity A.

It isn't possible. You see, the Activity has to pass through the onCreate() and onResume() callbacks for the UI to be changed.

Also, you should be using a bound Service to update the Activity when it returns to the foreground.

like image 95
Y.S Avatar answered Sep 20 '22 02:09

Y.S