Question

Ok so I have an android app with an Activity (UI) and a Service (background polling). The two are intricately connected using AIDL (including callbacks so it's duplex communication, IPC, whatever).

Any time the two talk I'm using that.

However I have also extended the Application class - so that the two can share common data objects. So the Application holds a User object that the Service is always using, and the Activity can also access it when it's running.

The Application also has a WeakReference to the Activity (to avoid context leaks) because the User will sometimes trigger UI updates.

So it looks like

Activity (UI) ---> Application <--- Service

I can trigger UI events within the Service by doing

_app = (FooApplication)this.getApplication();
FooActivity uiRef = _app.getUIReference().get();
if (uiRef != null) {
   uiRef.updateSomeDisplay();
}

So I don't get it. Why bother with complex AIDL calls when I just weak reference the UI, see if it exists, and call its methods.

Was it helpful?

Solution

The point of AIDL is to allow inter-process communication. The point of a service is to allow background operations to run in a separate process from your UI thread, so that they can continue running even if you close your app. You'll need AIDL, because your service will run in a completely different process from your UI, so you won't have access to memory in the UI process from your Service process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top