Alarm With Broadcast Receiver Not Working On Fragment
I'm working on a app with Fragments, One of the fragment includes alarm functionality. For this I have used broadcast receiver but don't understand why its not working: Here is th
Solution 1:
Why don't you try a custom BroadcastReceiver in place of your inline implementation? Try this
AlarmReceiver.java
publicclassAlarmReceiverextendsBroadcastReceiver {
@OverridepublicvoidonReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm time has been reached", Toast.LENGTH_LONG).show();
}
}
Register the receiver in AndroidManifest
<receiverandroid:name=".AlarmReceiver"android:process=":remote"/>
set the alarm in your SchedulerListFragment.java
Intentintent=newIntent(getActivity(), AlarmReceiver.class);
PendingIntentpendingIntent= PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
AlarmManageralarmManager= (AlarmManager)(getActivity().getSystemService( Context.ALARM_SERVICE ));
alarmManager.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + result , pendingIntent);
If you wish, you may register the BroadcastReceiver
dynamically using registerReceiver()
by passing an empty IntentFilter
. That will also work without any issues.
Post a Comment for "Alarm With Broadcast Receiver Not Working On Fragment"