I am trying to write an app that cannot be killed by a user or another application. I understand this goes against what Android has designed for its platform, this is more of a proof of concept. The plan is two have two apps, app1 and app2. When app1 starts it will start app2 and then bind onto app2, when app2 starts it will make sure app1 is started if not, then start it and bind onto app1. The point of app1 binding on app2 and app2 binding on app1 is so when one of them gets killed a method will be called that the binding has been disconnected and the app can then be restarted. I currently have the apps starting each other when they start up but I cannot seem to get them to restart when I force close one of them.
For App1 service I have and app2 very similar:
@Override
public void onCreate()
{
this.setForeground(true);
this.startService((new Intent()
.setComponent(new ComponentName("com.app2",
"com.app2.App2Service"))));
this.bindService((new Intent()
.setComponent(new ComponentName("com.app2",
"com.app2.App2Service"))), mConnection,
BIND_DEBUG_UNBIND);
And for my class that implements ServiceConnection I have:
@Override
public void onServiceDisconnected(ComponentName name)
{
Log.d(TAG, "onServiceDisconnected:" + name.getClassName());
mContext.startService((new Intent()
.setComponent(new ComponentName("com.app2",
"com.app2.App2Service"))));
}
I think the issue I am having is that onServiceDisconnected never gets called when app1 or app2 is killed. I think this may be because I am not correctly binding to a service.
W/JavaBinder( 884): ibinderForJavaObject: 0x436274a0 is not a Binder object
W/JavaBinder( 891): ibinderForJavaObject: 0x43621d30 is not a Binder object
So my question would be, how can I bind services together so when one gets force closed that I will get a notice on the other?