I have an application with a very simple UI. Most of the work (bulk processing of images) is done in background using AsyncTask.
It just has two Actvities. The first Activity(MainScreen) lets user make some choices and then fires off the job. The second screen(ProgressScreen) shows the current status of the job with a progressbar and messages.
It works fine.
Here’s the problem. The background task can take hours. If the user selects “back” button, while on ProgressScreen, the background task is still continuing.
Later if he wants to go back & see progress, there’s no way to do it. It I restart the app, it goes to the MainScreen, not the ProgressScreen. I know the background task is going on, since for now I am logging in logcat a message about each image being processed, but I just don’t see a way to go back to ProgressScreen.
I have looked around, I think I need to put something in the onStop() & onRestart() of the ProgressScreen, but not sure what…
I should mention, that this application not for general public, but is for internal use only. (We need to compare the image processing done by Android to those done by other systems).
You can try to put that processing logic inside a
Service(which are meant to run long time operations without user intervention). So, how can your second activity know what the progress of the task is? It can be done in different ways…ResultReceiverto the service and make it notify the progress to the activity from there.