Android PendingIntent

Android PendingIntent

Pending can be understood as a special kind of Intent, different from the intent executed immediately, PendingIntent intent is to be executed, as to when to perform the intent look at the following two examples will know

remind

 

 AlarmManger timing and execution cycle tasks, need to pass PendingIntent

Intent intent = new Intent(AlarmController.this, OneShotAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
                    0, intent, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);

See above code

A normal intent-> startXXX-> intent launched

A pendingIntent-> PendingIntent.getXXX () // indicate which type you want to start, Activity, broadcast, etc.

 

The following AlarmManger am introduced to a PendingIntent sender

Referred am start intent, to achieve regular tasks

 

Note that the distinction PendingIntent is requestcode, even if the same requestcode carry different data, either as the same PendingIntent, and the default will cover the original PendingIntent

 

Guess you like

Origin www.cnblogs.com/shineyoung/p/11575250.html