मैं पृष्ठभूमि सेवा पर काम कर रहा हूं कि सर्वर के लिए कुछ समय के लिए मतदान। मुद्दा यह है कि: मेरे पास एक इरादा सेवा है (जिसे अधिसूचना सेवा कहा जाता है) जो एक और सेवा कहता है, लेकिन इस अनुरोध की प्रतिक्रिया वापस नहीं आती है। और logcat में प्रकट होता है:एक मृत धागे पर एक हैंडलर को संदेश भेजना
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);
}
}
के लिए कोड है! चीयर्स!
संपादित करें: मुझे लगता है कि समस्या यह है कि लॉग "प्रतिक्रिया प्राप्त हुई" यह प्रकट नहीं होती है।
मैंने पहले से ही यही प्रश्न पढ़ा है लेकिन मैं अभी भी अटक गया हूं। मैं कहां श्रोता बनाने के लिए तैयार हूँ? – Mitodina