• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps intents vs. import

NubeeDrdGuy

Lurker
May 22, 2012
1
0
Why use intents to get info from an activity? Why not just import the class and use it directly in the .java file needing the info? Am I missing something obvious? New to Android programming - I am not having trouble coding with intents, just not sure why they are the preferred way of sharing info between activities.

Thanks in advance.
 
it allows information to pass between different applications?

Thats more or less it. Intents are basically an IPC (Inter Process Communication) mechanism. They allow you to ask other applications on the phone to do some work for you - for example you can ask to load a webpage and the users default browser will be started.

By importing packages you are just including an additional namespace in your application, which enables you to construct new types of objects. But any objects you create will be local to your process and not accessible by other applications on the system.

Intents also alow broadcasts. So you can notify multiple applications when interesting events occur (like when the USB cable is connected). And they allow for a more fine grained security model - in some instances you need special permissions to broadcast intents (like when you want to access the users contacts).
 
  • Like
Reactions: NubeeDrdGuy
Upvote 0
Android works by passing messages. Activities are UI instances. Only one UI instance can be active at a time. In order to fire up another instance even within your app you need to send a messages which will then properly "pause" your current activity and "create and/or resume" target activity.

Intents are used to deliver this message. There can be many types of messages. In your case it would be "an intent to start new UI activity"
 
  • Like
Reactions: NubeeDrdGuy
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones