Well, I agree with @Falmarri's comment, an easy way is to implement this using AsyncTask. Because AsyncTask controls UIThread and background thread.
I always do this with AsyncTask, but I don’t think pasting my code here will help you because your requirements may not be the same as mine, but I think you can do it this way;
Subclass AsyncTask and override these methods;
- onPreExecute () ... because this method is called on the user interface thread, which you can create and show a progress dialog.
doInBackground (Runnable task) ... this method runs in the background thread, so you don’t have to worry about processing the threads ... all you have to do is hard work
(data processing, data loading, etc.)
and post any UI update you want.
onProgressUpdate (Object ... values) ... this method is also called on the user interface thread, so you can update your
progress dialogue with progress
values.
onPostExecute (Object result) ... this method is executed in the user interface thread, so you can show the operation
result and reject progress
dialog box, and trigger your new activity.
You can perform all operations here, operation A and operation B, and AsynTask will manage the flow control for you :)
Change 1:
I don’t know how complicated your design is, but here I am making an example project, maybe this is not what you want, but there is everything that is described here in my answer, maybe how the example works.
I suggest you read more about this class, because it is one of the most important, here you can learn more about this mechanism ... http://android-developers.blogspot.com/2009/05/painless-threading.html
source share