Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2091354
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: LINUX

2010-10-23 23:24:14

  1. Tools
    • dumpsys
      Check if scheduled task is registered with:
      $ adb shell dumpsys alarm
    • xxx
  2. AlarmMamager
    • set/setRepeating
      Register a scheduled task. 4 types of alarm
        - ELAPSED_REALTIME: Alarm time in SystemClock.elapsedRealtime() (time since boot, including sleep). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.

        - ELAPSED_REALTIME_WAKEUP: Like ELAPSED_REALTIME bue will wake up the device when it goes off.

        - RTC: Alarm time in System.currentTimeMillis()  (wall clock time in UTC). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.

        - RTC_WAKEUP: Like RTC will wake up the device when it goes off.

      Notes: If alarm type is XXX_WAKEUP, and device is in sleeping mode, the alarm may be triggered several seconds ~ several minutes after the specified triggerring time.
    • xxx
  3. If timer is set to the past, the timer will be triggerd immediately. But it only be triggered once, no matter how much times it is.
  4. If set system time foreward and exceed triggerring time, the timer will be triggering, and it is triggered only once, no matter how much it is.
  5. Change system time backward won't trigger timer.
  6. Trigger alarm and complete the specified task even if the device is in sleeping mode.
    • Register alarm
      ...
      PendingIndent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
      alarm.set(AlarmManager.RTC_WAKEUP, time, sender);
      ...

      Notes: you can replace PendingIntent.getBroadcast with PendingIntent.getService or PendingIntent.getActivity

    • Lock power manager in Broadcast receiver/Service/Activity
      In the initiating interface (onReceive/onCreate), lock poer manager, then executing tasks, when the task is completed, release the power manager (Pay attation, user still can make device into sleeping mode by pressing Power key).
      • Lock power manager in onReceive/onCreate
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My lock name");
        wl.setReferenceCounted(true);
        wl.acquire();
      • Release power manager in onReceive/onDestroy
        if (wl != null)
        {
            wl.release();
            wl = null;
        }
      • You can verify if power wake lock is acquired or released with command
        $adb shell dumpsys power
        then search the specified tag when you invoke pm.newWakeLock()
      • xxx
    • Request permission in AndroidManifest.xml

    • xxx
  7. xxx
  8. ..
阅读(2465) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~