title: alarm manager service with wake lock
body: <p>I am using <code>AlarmManager</code> for scheduling things in my app, where the user will select the time and I am passing pending <code>intent</code> of my service class then to <code>AlarmManager</code> which should trigger the alarm after certain time when screen is on.</p>
  
  <p>It works properly but when the screen is locked, the alarm is not triggered.</p>
  
  <p>I have used <em>wakelock</em> with <em>partial wake lock</em> option in my service but it's not working.  When I used <em>full wake lock</em> then it works properly, so what is wrong with the partial lock option?</p>
  
  <p>Code posted below.</p>
  
  <pre><code>public void schedule(View v) {
      AlarmManager localAlarmManager = (AlarmManager)getSystemService("alarm");
      Calendar localCalendar = Calendar.getInstance();
  
      localCalendar.set(Calendar.HOUR_OF_DAY, 12);
      localCalendar.set(Calendar.MINUTE, 10);
      localCalendar.set(Calendar.SECOND, 0);
      Intent localIntent = new Intent(getBaseContext(), Backupservice.class);
      localIntent.putExtra("startservice", "true");
  
      PendingIntent localPendingIntent = PendingIntent.getService(getBaseContext(), 15, localIntent, 134217728);
      localAlarmManager.cancel(localPendingIntent);
      long l = localCalendar.getTimeInMillis();
  
      System.out.println("schtm:" + localCalendar.getTimeInMillis() +"currenttm:"+System.currentTimeMillis());
  
      localAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, l,1800000, localPendingIntent);
  }
  
  
  
  public class Backupservice extends Service {
  
      public Backupservice(){
          // cnt=context;
      }
  
      @Override
      public IBinder onBind(Intent arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public void onCreate() {
          miscallsettings=getSharedPreferences("MyPref", MODE_PRIVATE);
          Log.i("Backupservice", "Service created");
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          // TODO Auto-generated method stub
          super.onStartCommand(intent, flags, startId);
          PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  
          //  PowerManager.ACQUIRE_CAUSES_WAKEUP |
          wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK   |
                 PowerManager.ON_AFTER_RELEASE, "ggg");
          wl.acquire();
          save();
          return super.onStartCommand(intent, flags, startId);
      }
  
      @SuppressWarnings("unchecked")
      private void save() {
          try {
              // here I am writing the logic
              wl.release();
          } catch(Exception e) {
  
          }
      }
  
      @Override
      public void onDestroy() {
          try {
              wl.release();   
          } catch(Exception e) {
  
          }
      }
  }
  </code></pre>