Search code examples
androidandroid-alarmsandroid-broadcastandroid-pendingintent

android alarmmanager broadcast reciever not being called


hey guys was hoping you could help me out.

I am a novice anodroid developer using alarmManager for the first time, but the broadcast receiver dosent seem to be being called.

heres the code that creates the alarmManager

AlarmManager alarm=(AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
        Intent i=new Intent(this,AlarmReciever.class);
        PendingIntent p=PendingIntent.getBroadcast(this, 22, i,PendingIntent.FLAG_CANCEL_CURRENT);

        alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,1,p);

and the broadcast reciever class

Public class AlarmReciever extends BroadcastReceiver{

    @Override
    public void onReceive(Context c, Intent i) {
        // TODO Auto-generated method stub

        Toast toast1= Toast.makeText(c, "This text will be displayed \n on the toast", Toast.LENGTH_LONG);
        toast1.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
        toast1.show();

    }


}

Solution

  • Did you add the following code in your manifest ?

    <receiver
       android:name="AlarmReceiver"
       android:process=":remote" >
    </receiver>