Method Analysis of Intent Transfer object in Android development _android

Source: Internet
Author: User

In this paper, an example is given to analyze the method of intent passing objects in Android development. Share to everyone for your reference, specific as follows:

Method One:

Use method: Public Intent Putextra (String name, parcelable value) passes a parceable parameter that is serialized to memory.

Use method: Public Intent Putextra (String name, Serializable value) passes an object that implements the serialized interface class, and the argument of this method is serialized to disk.

Method Two:

Store the data in the "context" of the application, define the MyApplication class, let it inherit the application class, and deposit references to the relevant data in MyApplication. The code is as follows:

Import android.app.Application;
Import Cn.itcast.mobilesafe.domain.TaskInfo;
public class MyApplication extends application {public
  taskinfo tastinfo;
}

To configure application in the manifest file:

<application
    android:icon= "@drawable/ic_launcher"
    android:label= "@string/app_name" Android:name= " MyApplication ">
    <uses-library android:name=" Android.test.runner "/>

The data to be stored is stored in application:

Intent Intent = new Intent (taskmanageractivity.this, appdetailactivity.class);
MyApplication myApp = (myapplication) getapplication ();
Object obj = lv_task_manager.getitematposition (position);
if (obj instanceof taskinfo) {
  TaskInfo info = (taskinfo) obj;
  Myapp.tastinfo = info;
  StartActivity (intent);
}

More interested readers of Android-related content can view this site: "Introduction to Android Development and advanced Course", "Android Communication Summary", "Android Basic Components Usage Summary", "Android View Summary", " Android Layout layout Tips and a summary of the use of Android controls

I hope this article will help you with the Android program.

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.