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