Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Restart your schedule with AlarmManager after phone reboot

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 5.11k
    Comment on it

    When you create a schedule using AlarmManager and you found that it stops working after phone reboot. So to avoid this problem we need to add Broadcast receiver that should receive "BOOT_COMPLETED" broadcast.

    For this you need to register your BroadcastReceiver in android manifest file

    <receiver android:name=".BootReceiver">
          <intent-filter>
               <action android:name="android.intent.action.BOOT_COMPLETED" />
               <category android:name="android.intent.category.HOME" />
           </intent-filter>
    </receiver>
    

    Here BootReceiver is your BroadcastReceiver

    Now add the following permission in manifest:-

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    

    this permission is required to listen/reverie the BOOT_COMPLETED action.

    Create a BootReceiver like this:-

     public class BootReceiver extends BroadcastReceiver
        {    
           public void onReceive(Context context, Intent intent)
           {
              //  execute when Boot Completed
              /**Schedule your Alarm Here**/
             Toast.makeText(context, "Booting Completed", Toast.LENGTH_LONG).show();    
           }    
      }
    

    When boot completes, the onReceive method of BootReceiver wil execute. Here you can schedule your Alarm again or start your service again.
    Thanks

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: