2

onReceive()のメソッドで重い処理を行っているときに、このタイプのオフログがスローされることを私は知っていますBroadcastReceiver

しかし、これはonReceive()推奨される私のコードです:

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Iniciando classes   
    Intent iLocator = new Intent(context, LocatorService.class);
    context.startService(iLocator);
}

Intent は次の方法で送信されます。

public void agendarPing() {
    Intent it = new Intent("EXECUTA");
    PendingIntent p = PendingIntent.getBroadcast(LocatorService.this, 0,
            it, 0);

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    c.add(Calendar.SECOND, 360);

    long tempoReabrir = c.getTimeInMillis();
    AlarmManager reabrir = (AlarmManager) getSystemService(ALARM_SERVICE);
    reabrir.set(AlarmManager.RTC_WAKEUP, tempoReabrir, p);
    Log.d(TAG, "Alarme agendado com sucesso!");
    stopSelf();
}

なぜこのログが必要なのですか?

04-24 08:41:40.742: W/ActivityManager(1483): Timeout of broadcast BroadcastRecord{40b3f1c0 EXECUTA} - receiver=android.os.BinderProxy@40bcfef0, started 20008ms ago

04-24 08:41:40.742: W/ActivityManager(1483): Receiver during timeout: ResolveInfo{40b78208 br.com.contele.locator.LocatorReceiver p=0 o=0 m=0x108000}
4

1 に答える 1

0

Intent.FLAG_ACTIVITY_NEW_TASKはここでは役に立ちServiceませんActivity

また、なぜサービスを間接的に開始するのですか? 保留中のインテントだけで、あなたに代わってサービスを開始できます。

PendingIntent pi = PendingIntent.getService(mContext,1001,new Intent(LocatorService.class),PendingIntent.FLAG_CANCEL_CURRENT);

この保留中のインデントを に渡しAlarmManagerます。

于 2013-04-24T15:42:38.360 に答える