1.

What is Sticky Intent?

Answer»

In Android Sticky Intent is a type of Intent who will COMMUNICATE between Service and Function. Sticky Intent is using with Sticky Broadcast that’s why they are CALLING as StickyIntent. In simple language, we can say that StickyIntent is stick with till Broadcast is not completed its job this intent will be present and return data of registerReceiver() method and will be re-delivered or re-broadcasted to the future requests from any broadcast receivers.  We have one more advantage of Sticky Intent that Sticky Broadcast will replace the previous instance of the sticky broadcast and save your application from memory leak.

For example, if we need to SEND a notification for Low status of Battery, we will create a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED. As soon broadcast that action we will get the Intent with data. For this first, we need to add special permission in the manifest file that allows an application to broadcast sticky intents.

<uses-permission android:NAME="android.permission.BROADCAST_STICKY"/&GT;

Here's an example of how we can use a sticky broadcast for :

Intent intent = new Intent("action. ACTION_BATTERY_CHANGED"); intent.putExtra("status ", true); sendStickyBroadcast(intent);


Discussion

No Comment Found

Related InterviewSolutions