Day 6, androidday

Source: Internet
Author: User

Day 6, androidday

Pig's Android Getting Started Day 6

Android app core: Intent (Intent)

----- Reprinted with the source: coder-pig


This section introduces:


In the previous study, we all know that startActivity (intent) or startActivityForResult (intent) can be called)

To start a new Activity. Their parameters are Intent instances. So what is this Intent?

What is the purpose? There is another problem. I believe all of my friends have found that the activity tag of AndroidManifest. xml contains

Intent-filter, what is this? Well, with this, we can analyze the core of the android application a little bit.

Intent (Intent )!



This section describes the road map:



Analysis of learning roadmap:

① Understand what Intent is. Why did he use it?

② Distinguish between explicit Intent and implicit Intent to start an Activity in different ways!

③ Understand the seven attributes of Intent. If Flags does not understand it, You can temporarily put it

④ The process of activating a component using the display Intent and implicit Intent, as well as the predefined and custom actions of the implicit Intent!



Body:


Intent concepts:





Differences between explicit Intent and implicit Intent:




Seven attributes of Intent: ComponentName (component name ):



Action and Category ):




DATA and Type (MIME Type)




Extras (additional)




Flags)




Intent usage:


Explicit Intent:

This is one of the most frequently used methods in the past. Usually we start the second Activity. We only need to fill in

The fully qualified class name of the Activity. Call startActivity () or startActivityForResult ().


Code example: click the button to return to the HOME page

:



Core code:

Intent it = new Intent ();
It. setAction (Intent. ACTION_MAIN );
It. addCategory (Intent. CATEGORY_HOME );
StartActivity (it );



Code Example 2: click the button to open Baidu:

As follows:




Core code:

Intent it = new Intent ();
It. setAction (Intent. ACTION_VIEW );
It. setData (Uri. parse ("http://www.baidu.com "));
StartActivity (it );








Implicit Intent:






Implicit Intent of a predefined action:

Code example: After you click the button, all the activities whose actions are VIEW are filtered out and further selected by the user:

Run:


Core code process:

Create the layout of the second Activity, and add the code to the corresponding Activity by clicking the event button of the first Activity:

Intent it = new Intent ();
It. setAction (Intent. ACTION_VIEW );
StartActivity (it );

Add the following code to Intent:

<Activity android: name = ". SecondActivity"
Android: label = "second Activity">
<Intent-filter>
<Action android: name = "android. intent. action. VIEW"/>
<Category android: name = "android. intent. category. DEFAULT"/>
</Intent-filter>
</Activity>

The code is simple!




Implicit Intent of Custom Actions

Code example: use custom Action and category to activate another Activity

Run:


Note that although we have customized a category, we still need to add the default one. Otherwise, an error will be reported:

Add the following to the second activity tag of AndroidManifest. xml:

<Category android: name = "android. intent. category. DEFAULT"/>





Download related code:

Return to Home page: Download Code

Open the browser: Download the code

Implicit Intent containing predefined actions: Code download

Implicit Intent containing custom actions:Code download




Ps: for some predefined actions and Category of the system, you can write a blog post as needed!

Of course, you can also view the official documentation, In sdk --> docs --> reference --> android ---> content ---> Intent.html!




For more information about how to get started with android development, see android beginners.

The secrets of android Application Development are quite good. I suggest you go to the bookstore and choose not to buy the app. If you buy the app to Dangdang or excellence, the discount should be 44.90; let me give you a link, and there are also those related to Dangdang, which are also good. You can look at the Android 2.0 game development practices with a DVD teaching disk, but it is about the code. This is expensive. Let's take a look. Here are some links for you: product.dangdang.com/...773186;
Www.amazon.cn/...3ugk_p;
Product.dangdang.com/..ct-0-e

We all know that Android is based on the Linux 26 kernel, but the downloaded Android SDK does not see any Code related to Linux?

Android SDK is used to develop JAVA applications on Android. In addition, Android NDK is released. You can add link libraries written in C language. For Linux code, it can be found in the Android source code (only the compiled test image in the SDK ). Application Development does not use Linux code (embedded development is used, and the SDK is not responsible for underlying development ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.