Android learning notes bundle

Source: Internet
Author: User

1. Introduction

Used for data transmission between different activities

2. Important Methods

Clear(): Clear all stored data in this bundle ing.

Clone(): Clone the current bundle

Containskey(String key): returns the value of the specified key.

Getstring(String key): returns the character of the specified key.

Hasfiledescriptors(): Indicates whether to include any bundled package file descriptor.

Isempty(): Returns true if the binding ing is null.

Putstring(String key, string value): inserts the string value of a given key.

Readfromparcel(Parcel ):Read the content of this parcel.

Remove(String key): removes the value of a specified key.

Writetoparcel(Parcel, int flags ):Write the parcel content

Android2activity. Java

Package android2.test; </P> <p> Import android. app. activity; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. view. view. onclicklistener; <br/> Import android. widget. button; <br/> Import android. widget. edittext; </P> <p> public class android2activity extends activity {</P> <p> private edittext ET = NULL; <br/> private button = NULL; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> ET = (edittext) findviewbyid (R. id. edit); <br/> button = (button) findviewbyid (R. id. button); <br/> button. setonclicklistener (New buttonlistener (); <br/>}</P> <p> public class buttonlistener implements onclicklistener {</P> <p> Public void onclick (view arg0) {<br/> // todo auto-generated method stub <br/> bundle = new bundle (); <br/> bundle. putstring ("name", et. gettext (). tostring (); <br/> intent = new intent (android2activity. this, bundle. class); <br/> intent. putextras (bundle); <br/> startactivity (intent); <br/>}< br/>

Main. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <edittext <br/> Android: id = "@ + ID/edit" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"/> <br/> <button <br/> Android: Id = "@ + ID/button" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "start"/> <br/> </linearlayout>

Bundle. Java

Package android2.test; </P> <p> Import android. app. activity; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. widget. textview; </P> <p> public class bundle extends activity {<br/> private textview text = NULL; <br/> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. bundle); <br/> intent = getintent (); <br/> bundle = intent. getextras (); <br/> text = (textview) findviewbyid (R. id. text); <br/> text. settext (bundle. getstring ("name"); <br/>}</P> <p >}< br/>

Bundle. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <textview <br/> Android: id = "@ + ID/text" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> </linearlayout>

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.