The device is not plugged into cable for charging The device is set to sleep after 15s of inactivity
The weird outcome is that the vibrator keeps running every 60s when I set i to 60 here is my code for alarm.
public void startAlert(View view) {
EditText text = (EditText) findViewById(R.id.time);
int i = Integer.parseInt(text.getText().toString());
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this.getApplicationContext(), 234324243, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), i*1000, pendingIntent);
Toast.makeText(this, "Alarm set in " + i + " seconds",
Toast.LENGTH_LONG).show();
}
The BroadcastReceiver
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Time is up!!!!.",
Toast.LENGTH_LONG).show();
// Vibrate the mobile phone
Vibrator vibrator = (Vibrator) context
.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
}
You are confusing "sleep" with screen-off. You can't tell the device when to go into deep sleep mode.
As long as the processor is active, RTC will work. If the device goes to sleep (after 10 - 30 minutes of inactivity, depending on the device) you'll need RTC_WAKEUP.
So in your case, you might want to cancel the alarm when the screen turns off. See How can I tell if the screen is on in android? for more info.
Update
Just try it: play some music and wait 15 seconds. Will it stop? No. -> The device is not sleeping.
You can't set the time when the device will go to sleep because the system decides that. It's actually "display sleep". Imagine you're downloading an apk from the Play store. Should the download stop just because you told the device to "sleep" after X seconds? Of course not.
The setting in the menu is called "sleep" because the average user understands it. This setting is by the way accessible via Settings.System.putInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT, <int>).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With