Start the service to process the current event notifications - Android Android OS

Android examples for Android OS:Process

Description

Start the service to process the current event notifications

Demo Code

import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;

public class Main {

  static final Object mStartingServiceSync = new Object();
  static PowerManager.WakeLock mStartingService;

  /**//from w  w w.ja va 2 s. c o m
   * Start the service to process the current event notifications, acquiring the
   * wake lock before returning to ensure that the service will run.
   */
  public static void beginStartingService(Context context, Intent intent) {
    synchronized (mStartingServiceSync) {
      if (mStartingService == null) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mStartingService = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "StartingPopupUtilsService");
        mStartingService.setReferenceCounted(false);
      }
      mStartingService.acquire();
      context.startService(intent);
    }
  }

} 

Related Tutorials