• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android Alarm Manager and BroadcastReceiver

I have written some related code for AlarmManager App and a Toast Massage is shown in onReceive method in the BroadcastReceiver class. this is ok so for...

now i want to do something like writting a Toast massage in the activity, for sure i can not do that in onReceive method the question is that how can i do it in the activity?








Code:
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    vv();

    setRecurringAlarm(this);
   // dateShow();
  //  prefss();

}




private void setRecurringAlarm(Context context) {

    Calendar updateTime = Calendar.getInstance();
    //updateTime.setTimeZone(TimeZone.getTimeZone("GMT+5:00"));
    updateTime.setTimeZone(java.util.TimeZone.getTimeZone("GMT+5:00"));
    updateTime.set(Calendar.HOUR_OF_DAY,5);
    //updateTime.set(Calendar.MINUTE,31);
    updateTime.set(Calendar.MINUTE,49);
    updateTime.set(Calendar.SECOND,10);

    Intent intent = new Intent(context, BroadConnect.class);
    PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringDownload);


}

Code:
 public class BroadConnect extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {



      Toast.makeText(context,"ok" ,Toast.LENGTH_LONG).show();


}


}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones