The use of intent (intent) in Android

Source: Internet
Author: User

Overview:

Intent (Intent) is primarily to address communication between the various components of an Android application. Intent is responsible for the action of an operation in the application, the action involves data, the additional data is described, Android according to this intent description, is responsible to find the corresponding component, the intent passed to the calling component, and complete the call of the component. As a result, intent plays a role as a media intermediary, specifically providing information about the components that are called to each other, and decoupling the caller from the callee.

Category:Implicit intent

This method is inefficient by not specifying the activity to be opened, and by combining actions and data to find the interface in the system that can handle the specified actions and data.
Application Scenarios:
One app wants to be opened by another app.
One app wants to open another application.

To Open a method:

Open Code Intent Intent = New Intent () intent.setaction ("Com.test.rpcalc.CALC_RP"); Intent.setdata (Uri.parse ("calc://Zhang San "); Intent.addcategory (" Android.intent.category.DEFAULT "); StartActivity (intent);//The configuration of the open interface manifest file < Intent-filter >    <action android:name= "Com.test.rpcalc.CALC_RP"/> <data    android:scheme= "CALC"/ >    <!--Additional category parameters--    <category android:name= "Android.intent.category.DEFAULT"/></ Intent-filter>
An explicit intent

Specify (package name, class name) to jump directly. High efficiency.
Application Scenarios:
Jump between application's internal interface (secure)
Jump between apps can be configured for activity android:exported= "true", default false
Open Method

Mode one: Intent Intent = new Intent (this, selectnumberactivity.class); startactivity (Intent); mode two: Intent Intent = new Intent () ; Intent.setclassname ("Com.test.smssenderapp", "com.test.smssenderapp.SelectNumberActivity"); StartActivity ( Intent);
Intent data transfer

1.intent.setdata (URI)--intent.getdata ();
-Pass string data, more limited.
2.intent.putextra (name, value)
-8 large basic data types (Byte,short,int,long;float,double;char;boolean), and their arrays.

-String strings passed Charsequence
-Serializable Serialized Object (serialized to file) interface
-Parcelable Serialized Object (packet-to-memory) interface
-Bundle is a collection of data similar to map. Use Putextras ().

Methods for passing objects in intent:

One is bundle.putserializable (key,object);

The other is bundle.putparcelable (Key, Object);

The principle of choosing a serialization method:

1) When using memory, parcelable performance is higher than serializable, so we recommend using Parcelable.

2) serializable generates a large number of temporary variables at serialization time, resulting in frequent GC.

3) parcelable can not be used in the case of storing data on disk, because Parcelable does not guarantee the continuity of the data in the event of external change. Although serializable is inefficient, it is recommended to use serializable at this point.

Refer to the Post link:

the ways to pass objects in intent in Android " http://www.oschina.net/code/snippet_1408868_39329

"Parcelable interface usage in Android" http://www.cnblogs.com/renqingping/archive/2012/10/25/Parcelable.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The use of intent (intent) in Android

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.