Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does Alarm Manager persist even after reboot?

I am really new to android, I have been researching about alarms. I want to alarm if there is a birthday on that day. I've have used alarm manager. I was confused because i have read that it clears after reboot. I don't have an android phone so I'm just using the emulator.

Here's my code :

public void schedAlarm() {     AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);     Intent intent = new Intent(this, AlarmService.class);     pendingIntent = PendingIntent.getBroadcast(this, contact.id, intent, PendingIntent.FLAG_ONE_SHOT);     am.setRepeating(AlarmManager.RTC, timetoAlarm, nextalarm, pendingIntent); } 

I made this BroadcastRecever in replace for AlarmSerivce Here :

public void onReceive(Context context, Intent intent) {     nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);     CharSequence from = "It Birthday!";     CharSequence message =" Greet your friend.";     PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);     Notification notif = new Notification(R.drawable.ic_launcher, "Birthday", System.currentTimeMillis());     notif.setLatestEventInfo(context, from, message, contentIntent);     nm.notify(1, notif);  } 

is this enough??

like image 922
Xelamae Avatar asked Aug 20 '12 08:08

Xelamae


People also ask

How do I turn off alarm manager?

In order to delete : AlarmManager alarmManager = (AlarmManager) getSystemService(Context. ALARM_SERVICE); Intent myIntent = new Intent(getApplicationContext(), SessionReceiver. class); PendingIntent pendingIntent = PendingIntent.

How do I use Alarm Manager on Android?

This example demonstrates how do I use AlarmManager in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

A simple answer would be NO. But yes you can achieve this by creating a BroadCastReceiver which will start the Alarm while booting completes of the device.

Use <action android:name="android.intent.action.BOOT_COMPLETED" /> for trapping boot activity in BroadCastReceiver class.

You need to add above line in AndroidManifest.xml as follows,

<receiver android:name=".AutoStartUp" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">      <intent-filter>         <action android:name="android.intent.action.BOOT_COMPLETED" />     </intent-filter>     </receiver> 
like image 83
Lucifer Avatar answered Sep 21 '22 16:09

Lucifer


Yes , you can make AlarmManager to work even after rebooting. Perhaps this is the easiest way : add the below code in your AndroidManifest.xml:

<receiver android:name=".AlarmReceiver">         <intent-filter>             <action android:name="android.intent.action.BOOT_COMPLETED" />             <action android:name="android.intent.action.QUICKBOOT_POWERON" />              <category android:name="android.intent.category.DEFAULT" />         </intent-filter>     </receiver> 

don't forget to include user-permission to the AndroidManifest.xml as:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 
like image 20
Mohan Munisifreddy Avatar answered Sep 19 '22 16:09

Mohan Munisifreddy