I want to use an alarm manager in my activity. I set up an alarm at the onPause method of main activity like this,
Intent intent= new Intent(namaz_vakti_acti
I was facing the same problem and the most interesting thing was that it was working on Samsung Galaxy S duos but not Galaxy Nexus. My solution was to create a static lock in Broadcast reciever onReciever() method.
private static PowerManager.WakeLock wakeLock;
public static void acquireWakeLock(Context ctx) {
if (wakeLock != null)
wakeLock.release();
PowerManager pm = (PowerManager) ctx
.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE,
"aqs_wake_lock");
wakeLock.acquire();
}
public static void releaseWakeLock() {
if (wakeLock != null)
wakeLock.release();
wakeLock = null;
}
call acquireWakeLock() before calling startActivity() and then in OnCreate() method of launched activity I was playing the alarm sound after some delay i.e. in onPause() and on stopping alarm sound, I am finishing the activity and releasing the wakeLock by calling releaseWakeLock().
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
playSound(getApplicationContext(), getAlarmUri());
}
}, 1000);
Hope it will help for someone.