Pending Intent

What is Pending Intent?

Pending intent is an object that wraps another intent object with the target action to be performed.

It can be used to launch an activity,service,Broadcast receiver.

It is passed to other application to perform desired actions.

Types of Pending Intent?

getActivity(Context,int,Intent ,int);
getBroadcast(Context,int,Intent ,int);
getService(Context,int,Intent ,int);

Arguments of Pending Intent?

this(Context) – the context in which the PendingIntent starts the activity.

requestCode – a private request code for the sender.

intent – An explicit intent of the activity to be launched.

PendingIntent.FLAG_CANCEL_CURRENT – If described PendingIntent already exists,then cancel first once,and n new pending Intent is generated.

Broadcast Receiver

What is broadcast receiver?

It is an Application component.
Allows you to register for system or application events.
All registered receiver for an events are notified by android runtime once this event happens.
The broadcast can be generated either by system or by other application.
App can listen important System events such as Low battery,new Messages,System Reboot.

How to register broadcast receiver?

1.Statically – Declare in manifest file.
1.1.Broadcast receiver is declared in manifest.xml file like other components of android
1.2.Can’t be Unregistered.

2.Dynamically – In Java code
2.1.Broadcast receiver is registered using register() method.
2.2.Can Unregistered later.