コールバックを使用します。
ServiceInterface.aidl:
package com.test.service;
import com.test.service.ServiceCallback;
interface ServiceInterface {
/**
* Register callback for information from service.
*/
void registerCallback(ServiceCallback cb);
/**
* Remove a previously registered callback interface.
*/
void unregisterCallback(ServiceCallback cb);
}
ServiceCallback.aidl
package com.test.service;
/**
* Callback interface used by IRemoteService to send
* synchronous notifications back to its clients. Note that this is a
* one-way interface so the server does not block waiting for the client.
*/
oneway interface ServiceCallback {
/**
* Your callback function
*/
void onCallback(int data);
}
より多くのコードで説明しているMalachi の Androidサイトへのリンクを見つけました。