title: Android: Long running application stops responding. How to debug
body: <p>I have a long running <code>Service</code>, 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.</p>
  
  <p>The failure/bug never happens "on cable", so debugging on my local desktop machine does not work.</p>
  
  <p>I also written logs to disk, in order to follow the "flow" of the <code>Service</code>, but no failures happens (<code>MyService</code> does Network work, at least once every 20 seconds, but may be much more)</p>
  
  <p>I have a rooted Android device.</p>
  
  <p>In this device, I use Wifi (IEE802.11) to communicate with an ESP8266.</p>
  
  <p>For this, I have a Service, that runs indefinitely. I have "start" &amp; "stop" actions to control it. It is started and stopped by the following:</p>
  
  <p>MainActivity:</p>
  
  <pre><code>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;
      }
  };
  </code></pre>
  
  <p><code>MyService</code> is over 3k lines long, it has no blocking operations on itself, but holds <code>Thread</code>s that do, they seem to work correctly, even when the <code>MyService</code> stops responding to "Bound Activities".</p>
  
  <p>MyService:</p>
  
  <pre><code>@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;
      }
  }
  </code></pre>
  
  <p>As far as I can tell, when the "bug" happens, is when I bind an <code>Activity</code> (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.<h3>Update 25/10/2016</h3>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...</p>
  
  <p>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...</p>
  
  <p>I am attempting to monitor the device via Wifi adb. As soon as it completes, will post the results</p>