Changes

Jump to: navigation, search

Android Implicit Intents – An Android Studio Example

88 bytes added, 18:37, 19 January 2015
no edit summary
Launch Android Studio and create a new project, entering ImplicitIntent into the Application name field and ebookfrenzy.com as the Company Domain setting before clicking on the Next button.
On the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting to API 8: Android 2.2 (Froyo). Continue to proceed through the screens, requesting the creation of a blank activity named ImplicitIntentActivity with a corresponding layout and menu resource files named activity_implicit_intentand menu_implicit_intent respectively.
Click Finish to create the new project.
== 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 33-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_uiandroid_studio_implicit_intent_ui2.png|The user interface for an Android Studio based implicit intent tutorial]]
Figure 33-1
== Adding a Second Matching Activity ==
The remainder of this chapter will be used to demonstrate the effect of the presence of more than one activity installed on the device matching the requirements for an implicit intent. To achieve this, a second application will be created and installed on the device or emulator. Begin, therefore, by creating a new project within Android Studio with the application name set to MyWebView, using the same SDK configuration options used when creating the ImplicitIntent project earlier in this chapter. Select a blank activity and, when prompted, name the activity MyWebViewActivity and the layout layout and menu resource files activity_my_web_viewand menu_my_web_view.
== Adding the Web View to the UI ==
</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 the Designer toolbar buttons or the Properties panel so that the WebView fills the entire display area as illustrated in Figure 33-2:
[[Image:android_studio_web_view_intentandroid_studio_web_view_intent2.png|A WebView added to the Android Studio Implicit Intent example project]]
Figure 33-2
[[Image:android_studio_choose_activityandroid_studio_choose_activity2.png|Choosing an Activity for an Android Intent]]
Figure 33-4

Navigation menu