이 방법으로 처리하려고합니다 : BroadcastReceiver
시작 AlarmManager
반복 작업에서 의도를 IntentService
으로 보내면 서비스 로그가 기록됩니다. 로그에서 알 수 있듯이 BroadcastReceiver
은 수신 의도가 있으며 AlarmManager
을 시작하지만 IntentService
은 실행되지 않습니다. 여기서 무엇이 잘못 될 수 있습니까?AlarmManager를 사용하여 IntentService를 고칠 수 없습니다.
매니페스트 :
<receiver android:name=".wakefullBroadcastReciever.SimpleWakefulReciever" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="START"/>
</intent-filter>
</receiver>
<service
android:name=".wakefulService.NotificationWakefulIntentService"
android:enabled="true">
<intent-filter>
<action android:name="NOTIFY_INTENT" />
</intent-filter>
</service>
WakefulReciever :
public class SimpleWakefulReciever extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (!App.isRunning) {
Log.d("wakefull", "start");
Intent startIntent = new Intent(context, NotificationWakefulIntentService.class);
startIntent.setAction(Utils.NOTIFY_INTENT);
PendingIntent startPIntent = PendingIntent.getBroadcast(context, 0, startIntent, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP,
SystemClock.elapsedRealtime() + 3000, 5000, startPIntent);
App.isRunning = true;
}
}
}
IntentService :
public class NotificationWakefulIntentService extends IntentService {
public NotificationWakefulIntentService() {
super("NotificationWakefulIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("time",(System.currentTimeMillis()/1000)+"");
}
}