'com.commonsware.cwac.locpoll.LocationPoller'クラスを提供する非常に便利なCWAC-LocationPoller.jarライブラリ(Murphyをマークするための帽子のヒント)を使用しています。問題は、ロケーションポーリングアラームが発生するたびに、この警告が表示され続けることです。
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)
CWAC-LocationPollergithubダウンロードの一部として提供されている単純な「デモ」プロジェクトでもこの警告が表示されます。記録のために、デモプロジェクトの2つのJavaファイルのコピーを次に示します(著作権表示は簡潔にするために省略されています)。
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);
}
}
}
環境の詳細
- Eclipse IDE(バージョン4.2.0)
- ビルドターゲット:Android-8
- ターゲットデバイスAPIバージョン:Android-10(2.3.5)
- ターゲットデバイスモデル番号:Samsung Galaxy Y(GT-S5360)
ビルド済みのjarファイル(githubからダウンロード可能)とローカルでビルドされたバージョンのライブラリの両方を試してみましたが、同じ結果になりました。
任意の考え/アイデアをいただければ幸いです。私は本当にこの機能を使いたいです(私はすでに私のアプリで他のCWACの良さを使用しています)が、繰り返される警告について心配しています。
前もって感謝します)、
シッド