일정 기간 동안 서버에 폴링하는 백그라운드 서비스로 작업하고 있습니다. 요점은 : 나는 다른 서비스를 호출하는 IntentService (NotificationsService)가 있지만이 요청의 응답은 반환되지 않습니다. 그리고 로그 캣에 나타납니다죽은 스레드의 처리기에 메시지 보내기
06-19 05:12:00.151: W/MessageQueue(6436): Handler (android.os.Handler) {416659f0} sending message to a Handler on a dead thread
06-19 05:12:00.151: W/MessageQueue(6436): java.lang.RuntimeException: Handler (android.os.Handler) {416659f0} sending message to a Handler on a dead thread
06-19 05:12:00.151: W/MessageQueue(6436): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:196)
06-19 05:12:00.151: W/MessageQueue(6436): at android.os.Handler.sendMessageAtTime(Handler.java:473)
06-19 05:12:00.151: W/MessageQueue(6436): at android.os.Handler.sendMessageDelayed(Handler.java:446)
06-19 05:12:00.151: W/MessageQueue(6436): at android.os.Handler.post(Handler.java:263)
06-19 05:12:00.151: W/MessageQueue(6436): at android.os.ResultReceiver$MyResultReceiver.send(ResultReceiver.java:50)
나는 비슷한 여기에 문제를 보았다하지만 난 혼란있어 (내가 어떤 AsyncTask를 사용하지 않을거야, 난 CommonsWare 코드 wakefullIntent에 대해 검토 한하지만 난 그것을 이해하지 못했다).
은 여기 누군가가 나를 도울 수 있다면, 나는 그것을 많이 감사하겠습니다 NotificationsService.java
public class NotificationsService extends IntentService {
private static int TIME_INTERVAL_MILIS=90000;
private static final int REFRESH=10;
private NotificationManager noteManager;
private static List<FlightStatusNote> flights= new ArrayList<FlightStatusNote>();
public NotificationsService(){
super("NotificationsService");
}
@Override
public void onCreate(){
Log.d("notificationsSservice","onCreate");
super.onCreate();
noteManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("NotificationsService","Me llamaron");
Log.d("NotificationsService", "intervalo:"+NotificationsService.TIME_INTERVAL_MILIS);
Log.d("NotificationsService","Itero por cada vuelo registrado para notificar");
for(FlightStatusNote f: flights){
FlightStatus fly=f.getFlight();
Log.d("NotificationsService","Vuelo id:"+fly.getAirlineId()+fly.getNumberFlight());
Intent intentaux=new Intent(Intent.ACTION_SYNC,null,getBaseContext(),FlightStatusService.class);
intentaux.putExtra("airlineFlight", fly.getAirlineId());
intentaux.putExtra("numberFlight",fly.getNumberFlight());
intentaux.putExtra("receiver", new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
Log.d("notificationsService","response received");
if (resultCode == FlightStatusService.STATUS_OK) {
List<FlightStatus> fly = (List<FlightStatus>)resultData.getSerializable("return");
for(FlightStatus f: fly){
int indexNote=flights.indexOf(new FlightStatusNote(f,null));
FlightStatusNote fsNote=flights.get(indexNote);
List<String> changes=fsNote.hasChanged(f);
if(changes==null){
Log.d("notificationsService","changes is null");
}
else{
Log.d("notficationsService", "comething changed");
createNotification(f, changes);
}
}
}
}
});
startService(intentaux);
}
AlarmManager alarmMgr = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(getBaseContext(), DealAlarmReceiver.class), 0);
alarmMgr.set(AlarmManager.RTC, System.currentTimeMillis()+NotificationsService.TIME_INTERVAL_MILIS, pendingIntent);
}
}
의 코드입니다! 건배!
편집 : 문제는 Log "응답을 받았습니다"가 나타나지 않는다고 생각합니다. 활동에 그 핸들러 객체를 묶지 이유 (공정) 다음 코드를 나누기 있는지 -
나는 비슷한 질문을 이미 읽었지만 아직도 붙어 있습니다. 어디에서 청취자를 만들어야할까요? – Mitodina