Message transmission between activities. Bundle is a convenient method.
ProgramThe effect is that activity a redirects to B and sends a string while Activity B reads the string.
Define a new activity in androidmanifest. XML, target:
XML Code
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Ray. test"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". testbundle"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Activity Android: Name = ". Target"> </activity>
</Application>
<Uses-SDK Android: minsdkversion = "3"/>
</Manifest>
<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"
Package = "com. Ray. test"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name">
<Activity Android: Name = ". testbundle"
Android: Label = "@ string/app_name">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
<Activity Android: Name = ". Target"> </activity>
</Application>
<Uses-SDK Android: minsdkversion = "3"/>
</Manifest>
The code for the first activity is as follows:
Java code
Package com. Ray. test;
Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. View. motionevent;
Public class testbundle extends activity {
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
}
Public Boolean ontouchevent (motionevent event ){
Intent intent = new intent ();
Intent. setclass (testbundle. This, target. Class );
Bundle mbundle = new bundle ();
Mbundle. putstring ("data", "Ray 'blog"); // press data
Intent. putextras (mbundle );
Startactivity (intent );
Finish ();
Return super. ontouchevent (event );
}
Women's brand list
}
Package com. Ray. test;
Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. View. motionevent;
public class testbundle extends activity {
Public void oncreate (bundle savedinstancestate) {
super. oncreate (savedinstancestate);
setcontentview (R. layout. main);
}< br>
Public Boolean ontouchevent (motionevent event) {
intent = new intent ();
intent. setclass (testbundle. this, target. class);
bundle mbundle = new bundle ();
mbundle. putstring ("data", "Ray 'blog"); // press data
intent. putextras (mbundle);
startactivity (intent);
finish ();
return Super. ontouchevent (event);
}
activity code to jump to:
JAVA code
package COM. ray. test;
freight transport expert
Import android. app. activity;
Import android. OS. bundle;
public class target extends activity {
Public void oncreate (bundle savedinstancestate) {
super. oncreate (savedinstancestate);
setcontentview (R. layout. main);
bundle = getintent (). getextras ();
string data = bundle. getstring ("data"); // read data
settitle (data);
}