I like to do some long running initializing work in a remote service,
and during that, a progress dialog shall be shown.

So basicly, I invoke ProgressDialog.show, run a oneway method of the
service with a callback to be invoked when it's finished, and in the
callback dismiss the dialog.

I expected the service method to work in it's own process while the
activity shows the progress dialog.
But what happens instead (according to debugger and logs) is:
ProgressDialog.show and service method invocation return immediately,
then the service method is processed, and finally the progress dialog
is shown for a few milliseconds right before it's dismissed. Even a
"not responding" error might occur during that.
If I invoke the service method in an own thread, which (as it's to be
expected) is finished long before the service method is done,
everything works fine. But I don't get why this is necessary. Why does
a remote service method block the Activity thread? This even happens
if the service method only does a Handler.post and returns
immediately.

Simplyfied code overview:

Activity:

public void onStart() {
    startService(...);
    bindService(...);
}

public void onServiceConnected( ComponentName className, IBinder
service ) {
    service = IService.Stub.asInterface((IBinder)service);
    // showing dialog directly in service connection sometimes caused
troubles...
    handler.post( new Runnable() {
        public void run() {
            progressDlg = ProgressDialog.show( MyActivity.this, ... );
            service.longRunningMethod( callback );
        }
    }
}

ICallback callback = new ICallback() {
    public void callback() {
        progressDlg.dismiss();
    }
}

service.aidl:
oneway void longRunningMethod();

Service:
private final IService.Stub mBinder = new IService.Stub() {
    public void longRunningMethod() {
        // do something...
    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to