Elmi
Elmi

Reputation: 6203

Async program flow/show ProgressDialog

I have some code that a) needs about 10..20 seconds to execute b) returns a value that is used for further processing c) is called by the user

Thus I created a structure like this:

ProgressDialog pd = new ProgressDialog(ctx);  
pd.setCancelable(false);
pd.setCanceledOnTouchOutside(false);
pd.setTitle(ctx.getResources().getText(R.string.progress));
pd.setMessage(ctx.getResources().getText(R.string.wait_keygen));
pd.setIndeterminate(true);

returnValue=doSomeDifficultCalculationsHere();

pd.dismiss();

Now my problems is: the progress dialogue is not shown, it seems to be blocked by the blocking doSomeDifficultCalculationsHere()-function too.

When I place doSomeDifficultCalculationsHere() into an own thread and do a Thread.join() to wait for result of this function progress dialogue is also not shown because Thread.join() blocks.

When I put the ProgressDialog into the thread I get an exception.

So how else can I solve this problem and let the ProgressDialog be shown when I can't call doSomeDifficultCalculationsHere() really asynchronously because its result is needed for all following steps?

Thanks!

Upvotes: 0

Views: 48

Answers (1)

Apoorv
Apoorv

Reputation: 13520

You need to do pd.show() before returnValue=doSomeDifficultCalculationsHere();

Upvotes: 1

Related Questions