Thursday, August 1, 2013

Android: Wake Up - Mistakes that I made

I had been working on a very simple Android Alarm App.  The users would set up an alarm after certain period of time.  When the time for Alarm arrives, the BroadcastReceiver defined in our application receives a signal.  If the phone is in lock mode, we have to wake the phone up and display to the user that it is time.

To wake the phone up, I am using android.os.PowerManager and PowerManager.WakeLock.

  1. I had tried waking the phone up from inside BroadcastReceiver.  It should be done from Activity's onCreate() method.
  2. The parameters that I passed for getting a new WakeLock were not working right.  In fact, I don't know which is the correct parameter I should use.  I am now using a deprecated parameter which is the only thing that is working for me.  The method is PowerManager'sInstance.newWakeLock().  The first parameter is levelAndFlags - I am using PowerManager.SCREEN_DIM_WAKE_LOCK.  I know I will have to use a combination of different non-deprecated flags.  But, I have not figured it out yet.
  3. Always release the WakeLock in onFinish(), onPause(), onStop() methods.


No comments:

Post a Comment