Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle remote objects when an android service restarts?
    text
    copied!<p>I have created the following entities in Android :-</p> <ol> <li>Android MyService (apk)</li> <li>MyServiceClient (jar)</li> <li>MyApplication (uses MyService via MyServiceClient)</li> </ol> <p>For IPC, I have used AIDL. A sample implementation (of service client) is given below.</p> <p>AIDL interface - ICLAZZ.aidl(Implemented on the service side, and used internally for IPC with service) Service Client Side - CLAZZ.java (API exposed to developers)</p> <p>ICLAZZ.aidl</p> <pre><code>interface ICLAZZ { void doSomething(); } </code></pre> <p>CLAZZ.java</p> <pre><code>public class CLAZZ { private ICLAZZ mSvcInstance; //remote object // static method, instead of constructor for object creation due to some reason public static synchronized CLAZZ getInstance(inputParam) { // ICLAZZ remoteObject = get the remote object from service if(remoteObject!=null) { INSTANCE = new INSTANCE(inputParam); INSTANCE.mSvcInstance = remoteObject; } return INSTANCE; } private CLAZZ() { } private CLAZZ(inputParam) { // initialize based on inputParam } public void doSomething() { if(mSvcInstance!=null) mSvcInstance.doSomething(); } }; </code></pre> <p>When the API user calls CLAZZ.getInstance(), I create a remote object instance and save it in the local object of CLAZZ and return the CLAZZ object to the user. </p> <p>The problem that I am facing is, that in case where the service restarts, all the previous remote objects gets invalidated. However, the API user may have saved the CLAZZ object created earlier and might want to call some functionality on it. This will cause the application to fail. Also, I dont want to keep any global list of API objects created by the application. In the given scenario, is there some mechanism through which I can handle this situation gracefully and provide recovery for existing objects. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload