开发者

Android AIDL problem with activity and service

I'm writing an Android 2.1 app which supposed to display a dialog to the user when an external event triggers one of the GPIO's. I have written the Linux device driver, and written the JNI user-space interface to it. When my app start it launches a remote service which polls the device driver. With aidl, I managed to communicate between the activity and the service, however, when I'm closing the activity, I want the service to relaunch the activity. I achieved that using the following code: (in the servi开发者_Python百科ce)

Intent dialogIntent = new Intent(getBaseContext(),WiegandDemoActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(dialogIntent);

Right after that, I want to communicate using the aidl, so I used:

synchronized (listeners) {
for (WiegandListener listener : listeners) {
    try {
         listener.handleWiegandUpdated();
...

The activity is brought to front, however the aidl message doesn't reach it. why is that happening ? (when the activity is in front, everything works fine)

I didn't want to post all the code here because it's big, but if you need more information don't hesitate to ask.

Thanks.


You will need to re-bind to the remote Activity. Is it practical to have the Activity register to the service when it starts - so the update code is triggered when you know that the new Activity is ready to receive incoming messages?

Also be sure to un-register your event listener when your activity closes - otherwise it hangs around. If it contains a reference to the actual activity, then the whole activity remains in memory and doesn't get Garbage collected (even though it's closed and you've created a new one).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜