Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cost of raising an Intent in android

How much performance does it costs to broadcast intents? Is it okay to broadcast multiple per second or are intents expensive?

like image 905
Christian Avatar asked Mar 17 '11 15:03

Christian


People also ask

What is intent action in android?

An Intent is a messaging object you can use to request an action from another app component. Although intents facilitate communication between components in several ways, there are three fundamental use cases: Starting an activity. An Activity represents a single screen in an app.

What is intent and types of intent in android?

Intent is to perform an action. It is mostly used to start activity, send broadcast receiver, start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents.

What is intent and intent filter in android?

The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond. Intent filters are declared in the Android manifest file. Intent filter must contain <action>


2 Answers

Intents are meant to launch different activities within the Android OS or to inform about basic actions. It seems like a bad design pattern to use them otherwise. As they travel between different processes and therefore implement the Parcelable interface, they are not the most light-weight.

If you are looking to update different activities at the same time you might consider using a common service.

According to this blog post, intents are 10 times slower than direct function calls http://andytsui.wordpress.com/2010/09/14/android-intent-performance/

like image 170
Will Kru Avatar answered Sep 27 '22 21:09

Will Kru


It doesn't cost THAT much, but think of it the same way as you would a broadcast in a network environment. If you want to continually send a message to a device, you wouldn't send broadcasts every 100ms. That would just flood the network. Sending a broadcast once every, say, 10 seconds might be appropriate though.

What exactly the best implementation is entirely depends on what you're doing. In certain circumstances, if you have several services running that need to be run independently, and you're only broadcasting these intents that fast for say, 10 or 15 seconds. That might be ok.

But we can't really say.

like image 23
Falmarri Avatar answered Sep 27 '22 21:09

Falmarri