1

I'm using the very useful CWAC-LocationPoller.jar library (Hat Tip to Mark Murphy), which provides the 'com.commonsware.cwac.locpoll.LocationPoller' class. The trouble is, I keep getting this warning, seemingly every time the location polling alarm fires.

08-09 16:37:06.421: W/MessageQueue(31220): Handler{4055c2e8} sending message to a Handler on a dead thread
08-09 16:37:06.421: W/MessageQueue(31220): java.lang.RuntimeException: Handler{4055c2e8} sending message to a Handler on a dead thread
08-09 16:37:06.421: W/MessageQueue(31220):  at android.os.MessageQueue.enqueueMessage(MessageQueue.java:196)
08-09 16:37:06.421: W/MessageQueue(31220):  at android.os.Handler.sendMessageAtTime(Handler.java:457)
08-09 16:37:06.421: W/MessageQueue(31220):  at android.os.Handler.sendMessageDelayed(Handler.java:430)
08-09 16:37:06.421: W/MessageQueue(31220):  at android.os.Handler.sendMessage(Handler.java:367)
08-09 16:37:06.421: W/MessageQueue(31220):  at android.location.LocationManager$ListenerTransport.onStatusChanged(LocationManager.java:206)
08-09 16:37:06.421: W/MessageQueue(31220):  at android.location.ILocationListener$Stub.onTransact(ILocationListener.java:75)
08-09 16:37:06.421: W/MessageQueue(31220):  at android.os.Binder.execTransact(Binder.java:320)
08-09 16:37:06.421: W/MessageQueue(31220):  at dalvik.system.NativeStart.run(Native Method)

I'm getting this warning even with the simple 'demo' project that is provided as part of the CWAC-LocationPoller github download. Here are copies of the two java files in the demo project, for the record (copyright notices have been snipped for brevity).

LocationPollerDemo.java

package com.commonsware.cwac.locpoll.demo;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Toast;
import com.commonsware.cwac.locpoll.LocationPoller;

public class LocationPollerDemo extends Activity {
  private static final int PERIOD=1800000;  // 30 minutes
  private PendingIntent pi=null;
  private AlarmManager mgr=null;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mgr=(AlarmManager)getSystemService(ALARM_SERVICE);

    Intent i=new Intent(this, LocationPoller.class);

    i.putExtra(LocationPoller.EXTRA_INTENT,
           new Intent(this, LocationReceiver.class));
    i.putExtra(LocationPoller.EXTRA_PROVIDER,
           LocationManager.GPS_PROVIDER);

    pi=PendingIntent.getBroadcast(this, 0, i, 0);
    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                  SystemClock.elapsedRealtime(),
                  PERIOD,
                  pi);

    Toast
      .makeText(this,
            "Location polling every 30 minutes begun",
            Toast.LENGTH_LONG)
     .show();
  }

  public void omgPleaseStop(View v) {
    mgr.cancel(pi);
    finish();
  }
}

LocationReceiver.java

package com.commonsware.cwac.locpoll.demo;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import com.commonsware.cwac.locpoll.LocationPoller;

public class LocationReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    File log=
        new File(Environment.getExternalStorageDirectory(),
                 "LocationLog.txt");

    try {
      BufferedWriter out=
          new BufferedWriter(new FileWriter(log.getAbsolutePath(),
                                        log.exists()));

      out.write(new Date().toString());
      out.write(" : ");

      Bundle b=intent.getExtras();
      Location loc=(Location)b.get(LocationPoller.EXTRA_LOCATION);
      String msg;

      if (loc==null) {
        loc=(Location)b.get(LocationPoller.EXTRA_LASTKNOWN);

        if (loc==null) {
          msg=intent.getStringExtra(LocationPoller.EXTRA_ERROR);
        }
        else {
          msg="TIMEOUT, lastKnown="+loc.toString();
        }
      }
      else {
         msg=loc.toString();
      }

      if (msg==null) {
        msg="Invalid broadcast received!";
      }

      out.write(msg);
      out.write("\n");
      out.close();
    }
    catch (IOException e) {
      Log.e(getClass().getName(), "Exception appending to log file", e);
    }
 }
}

Environment Detail

  • Eclipse IDE (version 4.2.0)
  • Build Target: Android-8
  • Target Device API Version: Android-10 (2.3.5)
  • Target Device Model No.: Samsung Galaxy Y (GT-S5360)

I've tried with both the pre-built jar files (available for download from github) and locally built versions of the library, with the same result.

Any thoughts/ideas would be greatly appreciated. I really want to use this functionality (I'm already using other CWAC goodness in my app), but worry about the repeated warnings.

Thanks (in advance),

Sidd

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I will see if I can reproduce this warning, though for logistical reasons I may not be able to do so for a couple of days. – CommonsWare Aug 09 '12 at 12:14
  • So I did a bit more experimentation, and it may or may not have been a build problem. I ran it on both version 8 and version 10 emulators and did not see the warning. I then ran it on my Nexus One, and saw no warnings there either. When I saw that Android Version on the Nexus One (2.3.6) was newer than the Samsung Galaxy Y (2.3.5) I upgraded the phone software to 2.3.6 and... the problem went away. I'm happy to close this question, but we may still want to verify that the 2.3.5 flavor doesn't have issues with your code. – Delhi Ryder Aug 09 '12 at 12:59
  • (Update to the Update): The problems not gone, it's just become more intermittent. The Samsing Galaxy Y still sees this warning, which suggests there's a race condition somewhere. (End of investigation - at least for today) – Delhi Ryder Aug 09 '12 at 13:16
  • I cannot reproduce the problem on a Nexus S. I will try some other devices in the coming days to see if I can get it to occur. Somehow, the `PollerThread` is shutting down without going through `onPostExecute()`, and I am not seeing how that is possible. – CommonsWare Aug 12 '12 at 10:44

0 Answers0