I have a long running Service
, it works perfectly, however, after a couple hours, it stops responding (it appears to be executing, but it isn't). I wish to find out why/how.
The failure/bug never happens "on cable", so debugging on my local desktop machine does not work.
I also written logs to disk, in order to follow the "flow" of the Service
, but no failures happens (MyService
does Network work, at least once every 20 seconds, but may be much more)
I have a rooted Android device.
In this device, I use Wifi (IEE802.11) to communicate with an ESP8266.
For this, I have a Service, that runs indefinitely. I have "start" & "stop" actions to control it. It is started and stopped by the following:
MainActivity:
MyServices mMyServices = null;
boolean mIsBound = false;
onCreate(){
Intent myIntent = new Intent(this, MyServices.class);
startService(myIntent);
bindService(
myIntent,
myServiceConnection,
Context.BIND_AUTO_CREATE
);
}
onDestroy(){
unbindService(myServiceConnection);
stopService(new Intent(this, MyServices.class));
}
private final ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
MyServices.MyBinder binder = (MyServices.MyBinder) service;
mMyServices = binder.getService();
mIsBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
mIsBound = false;
}
};
MyService
is over 3k lines long, it has no blocking operations on itself, but holds Thread
s that do, they seem to work correctly, even when the MyService
stops responding to "Bound Activities".
MyService:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
private final IBinder mBinder = new MyBinder();
public class MyBinder extends Binder {
public MyServices getService() {
return MyServices.this;
}
}
As far as I can tell, when the "bug" happens, is when I bind an Activity
(several may be bound at once), then goes to background, after a couple hours, when a "Bound Activity" that was not on foreground goes to foreground, nothing happens, no Logs, no error, application just hangs, and ANR (Application Not Responding) message appears, and prompts to kill the application.
Update 25/10/2016
All binds have been removed and tested. The Service will halt operations, with no signs of the source of the failure at around 40 ~ 500 minutes. The device does a "exception happened" sound, its a Samsung SM-T810 tablet, nothing gets written to logs, no DDMS stacktrace, no path to follow...I do realise that the Service "crashed", its Threads and other parts will continue to work properly. It appears no code on the Service Object runs, attempts to writte to disk never succed. Debugging via cable has not yelded any usefull information on logs over 1 mb long...
I am attempting to monitor the device via Wifi adb. As soon as it completes, will post the results