我正在使用IntentService
准备闹钟,并在其中使用setAlarmClock
来设置闹钟。 IntentService
始终在适当的时间运行并设置警报(图标将显示),但警报将在100次中工作约99次。当一个警报失败时,每次警报都会发生类似的Intent
在您完全关闭应用程序之前会失败(requestsCode
中PendingIntent
的内容无关紧要。无论如何,在预定的闹钟时间之前的微秒,这称为:
09-19 16:10:59.996 1374-2126/? V/AlarmManager: Expired Alarm result :4
09-19 16:11:00.046 1374-2126/? D/VirtualScreenPolicy: applyVirtualScreenAttrs attrs=VirtualScreenAttrs{mDisplayId=0, mBaseDisplayId=0, mBaseActivity=false}
09-19 16:11:00.046 1374-2126/? D/GameManagerService: identifyGamePackage. com.simplyneededapps.ridealarm
09-19 16:11:00.046 1374-2126/? D/MultiWindowPolicy: Gamemode - return 0, when calling identifyForegroundApp(com.simplyneededapps.ridealarm)
09-19 16:11:00.066 1374-2126/? D/ActivityManager: mDVFSHelper.acquire()
09-19 16:11:00.066 1374-2126/? W/ActivityManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { flg=0x4 cmp=com.simplyneededapps.ridealarm/.MapAlarm VirtualScreenParam=Params{mDisplayId=-1, null, mFlags=0x00000000)} (has extras) }
09-19 16:11:00.116 23354-23354/? E/CocktailBarPositionManager: Window direction: 0
09-19 16:11:00.116 23354-23354/? I/CocktailBarPositionManager: updateAlphaScreenPosition position is dirty 0
如果有效,最终会调用Activity生命周期方法(onCreate,onResume,onStart ...):
09-19 16:45:00.048 1366-2124/? V/WindowManager: addAppToken: AppWindowToken{d09214481 token=Token{fb31868 ActivityRecord{8afbf8b u0 com.simplyneededapps.ridealarm/.MapAlarm t2738}}} to stack=2 task=2738 at 1
如果它没有运行Activity生命周期方法永远不会被调用,那就是:
09-13 10:05:00.379 1366-2124/? I/WindowManager: Screenshot max retries 4 of Token{d83f8b2 ActivityRecord{b762abd u0 com.simplyneededapps.ridealarm/.MainActivity t2491}} appWin=Window{6dec0a u0 d0 com.simplyneededapps.ridealarm/com.simplyneededapps.ridealarm.MainActivity} drawState=4
通常还有以下变体:
09-19 17:08:00.386 1374-1374/? D/SettingsProvider: isChangeAllowed() : name = next_alarm_formatted
09-19 17:08:00.386 2378-2378/? V/CenterBarWindowService: noteResumeComponent /arrangeState : 0
09-19 17:08:00.396 2302-2302/? D/KeyguardUpdateMonitor: handleTimeUpdate
09-19 17:08:00.396 1374-2587/? D/StatusBarManagerService: setIconVisibility slot=alarm_clock visible=false
09-19 17:08:00.406 2302-2302/? D/KeyguardUpdateMonitor: received broadcast android.intent.action.TIME_TICK
09-19 17:08:00.406 2302-2302/? D/KeyguardUpdateMonitor: handleTimeUpdate
09-19 17:08:00.416 1374-2628/? D/ActivityManager: post active user change for 0 fullscreen true isFloatingActivity() false isHomeActivity() false
09-19 17:08:00.416 1374-2628/? D/KnoxTimeoutHandler: postActiveUserChange [MsgParam] userId: 0 fullscreen is true showWhenlocked is false
09-19 17:08:00.426 1374-1374/? D/GameManagerService: NotifyRunnable. pkg: com.simplyneededapps.ridealarm, type: 4, isMinimized: false, isTunableApp: false
09-19 17:08:00.426 1374-1374/? D/GameManagerService: do nothing. mKillNotiCount: 3
09-19 17:08:00.426 2302-2302/? D/Clock: received broadcast android.intent.action.TIME_TICK
09-19 17:08:00.436 1374-1374/? D/KnoxTimeoutHandler: handleActiveUserChange [MsgParam] userId: 0 fullscreen is true showWhenlocked is false
09-19 17:08:00.446 1374-1374/? I/KnoxTimeoutHandler: Shared devices show user statefalse
09-19 17:08:00.486 1374-2587/? V/WindowStateAnimator: Finishing drawing window Window{c666b94 u0 d0 com.simplyneededapps.ridealarm/com.simplyneededapps.ridealarm.MainActivity}: mDrawState=HAS_DRAWN
09-19 17:08:00.506 18924-18924/com.simplyneededapps.ridealarm V/ActivityThread: updateVisibility : ActivityRecord{11d12c8 token=android.os.BinderProxy@98ab18f {com.simplyneededapps.ridealarm/com.simplyneededapps.ridealarm.MainActivity}} show : true
09-19 17:08:00.506 18924-18924/com.simplyneededapps.ridealarm I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@98ab18f time:64852633
09-19 17:08:00.546 2302-2302/? D/DateView: received broadcast android.intent.action.TIME_TICK
在我的IntentService中:
@Override
protected void onHandleIntent(Intent intent) {
//about 200 lines setting up the alarm
AlarmManager alarmMgr;
PendingIntent pIntent;
alarmMgr = (AlarmManager) context2.getSystemService(Context.ALARM_SERVICE);
Intent intent2 = new Intent(context2, MapAlarm.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent2.putExtra("id",id)
pIntent = PendingIntent.getActivity(context2, (int) id, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo(next,pIntent);
alarmMgr.setAlarmClock(alarmClockInfo,pIntent);
}else{
alarmMgr.setExact(AlarmManager.RTC_WAKEUP, next, pIntent);
}
stopService(intent);
}
有没有办法始终确保始终调用onCreate
或至少onResume
,无论如何?我仍然无法确定直接原因所以任何和所有的帮助将不胜感激!