1

Again i have a problem with Broadcasts..

Fragment:

Intent i = new Intent(context,AlarmReceiver.class);
i.setAction(Intent.ACTION_BOOT_COMPLETED);
int id = (int) alarms_ID;
i.putExtra("_id",id);

PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, i, PendingIntent.FLAG_UPDATE_CURRENT);
Calender calender=...;
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

BroadcastReceiver:

public void onReceive(Context context, Intent intent) {
  Toast.makeText(context,"yap",Toast.LENGTH_SHORT).show();
}

and the receiver in manifest:

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

very simple code but still not working... This code work in activity maybe the problem is the fragment? If you need more information just say it.

9
  • I have edited my answer, replace context with getActivity() Jul 2, 2015 at 21:17
  • Code looks good. Paste code after calendar maybe you have a mistake. Jul 2, 2015 at 21:36
  • @krystian71115 I thought so too but i checked the year,month,day,hour and minute and they are all in time the datepicker and timepicker defined.. Edit : you are right...i replaced calender with System.currentTimeMillis() and this is work but the Calender is ok... Jul 2, 2015 at 21:46
  • If you are calling this from other thread try runOnUiThread method in the activity and not use static fields to get context use parameter of method. Jul 2, 2015 at 21:50
  • 1
    @krystian71115 as you said the problem was the calendar. i add 1 to the month because it based on zero count and i forgot to subtract 1 from month.. thank you a lot of your time and help !! Jul 3, 2015 at 9:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.