Changes

Jump to: navigation, search

Android Implicit Intents – An Android Studio Example

No change in size, 15:22, 18 July 2014
no edit summary
== Designing the User Interface ==
The user interface for the ImplicitIntentActivity class is very simple, consisting solely of a RelativeLayout view and a button. Within the Project tool window, locate the ImplicitIntent -> app -> src -> main -> res -> layout -> activity_implicit_intent.xml file and double click on it to load it into the Designer tool. Visually construct the user interface in Design mode so that it resembles Figure 3133-1, or enter the following XML in Text mode. Note that in both cases, the text on the button (“Show Web Page”) has been extracted to a string resource named button_text:
<pre>
[[Image:android_studio_implicit_intent_ui.png|The user interface for an Android Studio based implicit intent tutorial]]
Figure 3133-1
</pre>
Return to the Designer tool to Design mode and drag and drop a WebView object from the Widgets section of the palette onto the existing RelativeLayout view. Set the layout height and width properties to match_parent using either Designer toolbar buttons or the Properties panel so that the WebView fills the entire display area as illustrated in Figure 3133-2:
[[Image:android_studio_web_view_intent.png|A WebView added to the Android Studio Implicit Intent example project]]
Figure 3133-2
== Installing the MyWebView Package on a Device ==
Before the MyWebViewActivity can be used as the recipient of an implicit intent, it must first be installed onto the device. This is achieved by running the application in the normal manner. Because the manifest file contains neither the android.intent.action.MAIN nor the android.intent.category.LAUNCHER directives, however, Android Studio does not know whether or not to launch the activity once the application has been installed on the device. Consequently, Android Studio will display the Edit configuration dialog illustrated in Figure 31 33-3 when the application is run, requesting instructions on how to proceed once the application package has been installed.
[[Image:android_studio_do_not_launch2.png|Editing the run configuration for an application in Android Studio]]
Figure 3133-3
== Testing the Application ==
In order to test MyWebView, simply re-launch the ImplicitIntent application created earlier in this chapter and touch the Show Web Page button. This time, however, the intent resolution process will find two activities with intent filters matching the implicit intent. As such, the system will display a dialog (Figure 31 333-4) providing the user with the choice of activity to launch.
[[Image:android_studio_choose_activity.png|Choosing an Activity for an Android Intent]]
Figure 3133-4

Navigation menu