Finding and Using the Launch Intent Within an Activity

When an application component is started through an implicit Intent, it needs to find the action it's to perform and the data to perform it on.

Call the getIntent method —usually from within the onCreate method —to extract the Intent used to start a component, as in Listing 5-8.

STING 5-8: Finding the launch Intent in a sub-Activity

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main);

Intent intent = getIntent();

Use the getData and getAction methods to find the data and action associated with the Intent. Use the type-safe get<type>Extra methods to extract additional information stored in its extras Bundle.

String action = intent.getAction(); Uri data = intent.getData();

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment