Use of Intent (Intent) in Android, androidintent

Source: Internet
Author: User

Use of Intent (Intent) in Android, androidintent
Overview:

Intent mainly solves the communication between various components of Android applications. Intent describes the actions, actions involving data, and additional data of an application. Android identifies the corresponding components based on the description of the Intent, pass Intent to the called component and complete the call of the component. Therefore, Intent acts as a media intermediary here, providing information about component calls to each other to decouple callers from callers.

Category: Implicit intent

You do not need to specify the activity to be opened. You can search for the system by combining the action and data to process the interface of the specified action and data. Therefore, this method is less efficient.
Application scenarios:
One application wants to be opened by another application.
One application wants to open another application.

Enabling method:

// Enable the code Intent intent = new Intent (); intent. setAction ("com. test. rpc1c. CALC_RP "); intent. setData (Uri. parse ("calc: // Zhang San"); intent. addCategory ("android. intent. category. DEFAULT "); startActivity (intent); // configuration of the list file of the opened interface <intent-filter> <action android: name =" com. test. rpc1c. CALC_RP "/> <data android: scheme =" calc "/> <! -- Additional category parameter --> <category android: name = "android. intent. category. DEFAULT"/> </intent-filter>
Explicit intent

Specify (package name, class name) and directly jump. High efficiency.
Application scenarios:
Redirection (Security) between internal application interfaces)
To redirect between applications, you can configure android: exported = "true" for the Activity. The default value is false.
Enabling Method

Method 1: Intent intent = new Intent (this, SelectNumberActivity. class); startActivity (intent); Method 2: Intent intent = new Intent (); intent. setClassName ("com. test. smssenderapp "," com. test. smssenderapp. selectNumberActivity "); startActivity (intent );
Intent Data Transmission

1. intent. setData (uri) -- intent. getData ();
-It is relatively limited to transmit string data.
2. intent. putExtra (name, value)
-8 basic data types (byte, short, int, long; float, double; char; boolean) and their arrays.

-String CharSequence
-Serializable: serialization object (serialized to a file) Interface
-Parcelable: serialization object (package to memory) Interface
-Bundle is similar to a map data set. Use putExtras ().

Methods for passing objects in Intent:

One is Bundle. putSerializable (Key, Object );

The other is Bundle. putParcelable (Key, Object );

Principles for selecting serialization methods:

1) when using memory, Parcelable has higher performance than Serializable, so Parcelable is recommended.

2) Serializable will generate a large number of temporary variables during serialization, resulting in frequent GC.

3) Parcelable cannot be used when you want to store data on a disk, because Parcelable cannot guarantee data continuity in the case of external changes. Although the Serializable efficiency is low, we recommend using Serializable.

 

Refer to the blog post link:

Http://www.oschina.net/code/snippet_1408868_39329 of the method for passing objects in Intent in Android

The use of Parcelable interface in Android http://www.cnblogs.com/renqingping/archive/2012/10/25/Parcelable.html

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.