Code example for PowerManager

Methods: newWakeLock

0
    static void runIntentInService(Context context, Intent intent) {
        if (mWakeLock == null) {
            // This is called from BroadcastReceiver, there is no init. 
            PowerManager pm = 
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
                    WAKELOCK_KEY);
        } 
        mWakeLock.acquire();
        
        // Use a naming convention, similar with how permissions and intents are  
        // used. Alternatives are introspection or an ugly use of statics.  
        String receiver = context.getPackageName() + ".C2DMReceiver";
        intent.setClassName(context, receiver);
         
        context.startService(intent);
 
    } 
     
     
    private void handleRegistration(final Context context, Intent intent) {