如何在报警接收器中的广播接收器中显示UI上的数据

时间:2015-09-15 07:59:18

标签: android alarmmanager

我必须在UI上5秒后更新数据。我正在使用Alarm Manager但不知道在UI上显示数据。

AlarmReceiver:

public class AlarmReceiver extends BroadcastReceiver {

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

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

从主要活动中调用:

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);

0 个答案:

没有答案