1. Download our Official Android App: Forums for Android!
  2. Download the #1 Android News App:   EarlyBird - News for Android
    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 (Text):
    1.  @Override
    2. protected void onCreate(Bundle savedInstanceState) {
    3.     super.onCreate(savedInstanceState);
    4.     setContentView(R.layout.activity_main);
    5.  
    6.     vv();
    7.  
    8.     setRecurringAlarm(this);
    9.    // dateShow();
    10.   //  prefss();
    11.  
    12. }
    13.  
    14.  
    15.  
    16.  
    17. private void setRecurringAlarm(Context context) {
    18.  
    19.     Calendar updateTime = Calendar.getInstance();
    20.     //updateTime.setTimeZone(TimeZone.getTimeZone("GMT+5:00"));
    21.     updateTime.setTimeZone(java.util.TimeZone.getTimeZone("GMT+5:00"));
    22.     updateTime.set(Calendar.HOUR_OF_DAY,5);
    23.     //updateTime.set(Calendar.MINUTE,31);
    24.     updateTime.set(Calendar.MINUTE,49);
    25.     updateTime.set(Calendar.SECOND,10);
    26.  
    27.     Intent intent = new Intent(context, BroadConnect.class);
    28.     PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    29.     AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    30.  
    31.     alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, recurringDownload);
    32.  
    33.  
    34. }
    Code (Text):
    1.  public class BroadConnect extends BroadcastReceiver {
    2.  
    3. @Override
    4. public void onReceive(Context context, Intent intent) {
    5.  
    6.  
    7.  
    8.       Toast.makeText(context,"ok" ,Toast.LENGTH_LONG).show();
    9.  
    10.  
    11. }
    12.  
    13.  
    14. }
     

Share This Page

Loading...