Android 稍后运行意图
示例
创建一个接收器。这堂课将收到您的意图并按照您的意愿进行处理。
public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //处理意图 int reqCode = intent.getExtras().getInt("requestCode"); ... } }
给AlarmManager一个意图。此示例将在1分钟后触发将意图发送到AlarmReceiver。
final int requestCode = 1337; AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); am.set( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 60000 , pendingIntent );