Sunday, 15 June 2014

android - Service callback throws: Uncaught remote exception! (Exceptions are not yet supported across processes.) -



android - Service callback throws: Uncaught remote exception! (Exceptions are not yet supported across processes.) -

i'm having issues callbacks. here code:

activity:

private icallback callback = new icallback.stub() { @override public void fire() throws remoteexception { mtextview.settext("fired"); } }; //then in oncreate add: mmanger.registercallback(callback);

icallback (aidl)

interface icallback { void fire(); }

manager:

public void registercallback(icallback callback) { seek { mservice.registercallback(callback); } grab (remoteexception e) { log.e(tag, "service dead"); } } private void notifycallbacks() { seek { mservice.notifycallbacks(); } grab (remoteexception e) { log.e(tag, "service dead"); } }

service:

public void registercallback(icallback callback) { if (callback != null) { mcallbacks.register(callback); } } public void notifycallbacks() { final int n = mcallbacks.beginbroadcast(); (int i=0;i<n;i++) { seek { mcallbacks.getbroadcastitem(i).fire(); } grab (remoteexception e) { } } mcallbacks.finishbroadcast(); }

my callbacks notified run when seek set textview text:

e/javabinder﹕ * uncaught remote exception! (exceptions not yet supported across processes.) android.view.viewrootimpl$calledfromwrongthreadexception: original thread created view hierarchy can touch views.

like error message says, seek update view wrong thread. fire() method called remote service runs in thread, need create sure, code updates ui runs in ui thread. accomplish this, seek following:

public void fire() throws remoteexception { //the activity provides method able run code in ui thread runonuithread(new runnable(){ @override public void run(){ mtextview.settext("fired"); } }) }

android service callback android-service aidl

No comments:

Post a Comment