두 개의 서비스가 실행 중입니다. 그들은 자신의 작업을 수행 한 다음 AlarmManager를 통해 스스로 일정을 재조정합니다. BroadcastReceiver에서 일어나는 유일한 일은 Context.startService()를 통한 서비스 시작입니다. 두 서비스 모두 IntentServices이며 타임 아웃 문제가 발생하지 않아야한다고 알 수 있습니다. 나는 IntentServices, 스레딩 및 AsyncTasks를 시도했지만 수신자 자신의 시간 초과 오류에 대해 반복적으로 충돌하고 있습니다.IntentServices를 사용하는 BroadcastReceivers의 시간 초과
타임 아웃 메시지이다 01-18 11 : 29 : 04.200 : 경고/ActivityManager (73), 방송 시간 종료 BroadcastRecord 433a4168 my.package.action.a {} - [email protected] 01-18 11 : 29 : 04.210은 : 경고/ActivityManager (73) : 타임 아웃 동안 수신기 : ResolveInfo {43394a30 my.package.MyReceiverA를 p = 0 O = 0, m = 0x108000}
두 수신기의 기본 구조 :
public class MyReceiverA extends BroadcastReceiver {
public static final String ACTION_TO_BROADCAST = "my.package.action.a";
public void onReceive(Context context, Intent intent) {
// start the service
Intent serviceIntent = new Intent().setClassName(context,
MyServiceA.class.getName());
context.startService(serviceIntent);
}
}
그리고 서비스 :
공용 클래스 MyServiceA는 IntentService를 확장합니다. { public ActivityMonitorService() { super (TAG); 은}
public IBinder onBind(Intent intent) {
// We don't allow anyone to bind to us
return null;
}
public void onCreate() {
super.onCreate();
_context = getApplicationContext();
_config = new Config();
if (_handler == null) {
_handler = new Handler();
}
}
/**
* Schedules an alarm to run ourselves again after ALARM_INTERVAL has passed.
*/
private void reschedule() {
Intent intent = new Intent(MyReceiverA.ACTION_TO_BROADCAST);
PendingIntent pendingIntent = PendingIntent.getBroadcast(_context, 0, intent, 0);
AlarmManager manager = (AlarmManager) _context.getSystemService(Context.ALARM_SERVICE);
manager.set(AlarmManager.RTC, now + delay, pendingIntent);
}
private void doWork() {
// Do some work. This could take a while. It also accesses a database that the two
// services share through synchronized blocks of code in static accessor functions.
}
protected void onHandleIntent(Intent intent) {
try {
doWork();
} catch (Exception e) {
// log it
} finally {
reschedule();
}
}
}
관련없는 팁 :'새로운 의도() .setClassName (context, MyServiceA.class.getName())'→'새로운 의도 (context, MyServiceA.class) ' –
'서비스 코드 'Context'에 대한 참조를 ('_context'처럼) 유지하는 것과 같습니다. 'onCreate()'중에 anythin을하고 있습니까, 아니면 다른 메소드를 무시하고 있습니까? –
재정의 된 함수에서 편집 됨. –