0

I have to update data after 5 seconds on UI. I am using Alarm Manager but having no idea to show the data on UI.

AlarmReceiver:

public class AlarmReceiver extends BroadcastReceiver {

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

    Toast.makeText(context, "alarm", Toast.LENGTH_LONG).show();
}

calling from Main Activity:

Intent intentAlarm = new Intent(this, AlarmReceiver.class);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0,
            intentAlarm, 0);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis(), 2000, pi);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Developer
  • 67
  • 10
  • 1
    this will help http://stackoverflow.com/questions/14643385/how-to-update-ui-in-a-broadcastreceiver – Jibran Khan Sep 15 '15 at 08:00
  • You should not use the AlarmManager for updating the UI, you should be using TimerTasks: http://developers.androidcn.com/resources/articles/timed-ui-updates.html – Rolf ツ Sep 15 '15 at 08:05

0 Answers0