0

I'm trying to show a spinning progress dialog until my activity calls the method finish(). I call progressDialog.show() right before I call finish(). I can see the spinner, but it is not spinning...any suggestions?

I tried to put the finish() and the stuff which gets called in onActivityResult() of the other activity in background threads, so the ui-thread shouldn't have to do something. When I'm debugging and I wait at the finish() method on another thread than the main thread, the progress dialog is spinning...when I go one step further and call the finish() method, the progress dialog stops spinning and after 1-2 seconds the activity disappears.

So my only suggestion is that the finish() method is the reason for the not moving progress dialog...is there a possibility to get it moving?

Thanks in advance!

Edit: That code is inside activity A which gets finished.

private void goBack() {
    setResult((mReopen) ? Constants.RESULT_REOPEN : RESULT_OK);
    if (mReopen) {
        mProgressDialog.show();
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            finish();
        }
    }).start();
}

That code is inside the activity B which starts activity A.

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    if (requestCode == Constants.REQUEST_CODE_OPEN_EMAG) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                switch (resultCode) {
                    case Constants.RESULT_REOPEN:
                        mReopen = true;
                        openEmag(mLastOpenedEmagId, false, false);
                        break;
                    default:
                        mReopen = false;
                        break;
                }
            }
        }).start();
    }
}

As you can see all the stuff gets called in different threads than the ui-thread.

tobi_b
  • 1,218
  • 1
  • 12
  • 21

1 Answers1

0

finsih() stops your activity and exits it. What do you mean background thread*s*?

You should have one background thread for heavy operations and call finish() at the end of that thread.

Like this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == yourCode) {
        if (resultCode == RESULT_OK) {
            //... Do dialog.show() here
            new Thread(){
                public void run() {
                    //... Your stuff here
                    finish();
                };
            }.start();
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
Alex Orlov
  • 18,077
  • 7
  • 55
  • 44
  • yeah, that's exactly what I'm doing, pls see the code of the edit – tobi_b Oct 02 '12 at 15:40
  • new Thread ... finish() ... will execute your finish almost immediately. And since you start dialog in your modal activity it won't show for long, since finish() is called right after show(). – Alex Orlov Oct 03 '12 at 07:23
  • In new Thread().. you should put long running code that should run on the background (like my example) and call finish in the thread after your code completes (my example again). Dialog on the other hand should be started on UI thread. – Alex Orlov Oct 03 '12 at 07:25