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">
- <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 "> <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
- PackageCom. Ray. test;
-
-
- ImportAndroid. App. activity;
-
- ImportAndroid. content. intent;
-
- ImportAndroid. OS. Bundle;
-
- ImportAndroid. View. motionevent;
-
-
- Public ClassTestbundleExtendsActivity {
- Public VoidOncreate (bundle savedinstancestate ){
-
- Super. Oncreate (savedinstancestate );
-
- Setcontentview (R. layout. Main );
-
- }
-
-
- Public BooleanOntouchevent (motionevent event ){
- Intent intent =NewIntent ();
-
- Intent. setclass (testbundle.This, Target.Class);
-
- Bundle mbundle =NewBundle ();
-
- Mbundle. putstring ("Data","Ray 'blog");// Press data
-
- Intent. putextras (mbundle );
- Startactivity (intent );
-
- Finish ();
-
- Return Super. Ontouchevent (event );
-
- }
-
- }
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 = new intent (); intent. setclass (testbundle. this, target. class); bundle mbundle = new bundle (); mbundle. putstring ("data", "Ray 'blog"); // press the data intent. putextras (mbundle); startactivity (intent); finish (); return Super. ontouchevent (event );}}
Activity Code to jump:
Java code
-
- PackageCom. Ray. test;
-
- ImportAndroid. App. activity;
-
- ImportAndroid. OS. Bundle;
-
-
- Public ClassTargetExtendsActivity {
-
-
- Public VoidOncreate (bundle savedinstancestate ){
-
- Super. Oncreate (savedinstancestate );
- Setcontentview (R. layout. Main );
-
- Bundle bundle = getintent (). getextras ();
-
- String data = bundle. getstring ("Data");// Read data
-
- Settitle (data );
-
- }
-
- }
If you want to return data/information from target to testbundle, you can:
Startactivityforresult (intent, 1333); // 1333 is the Request Code
Then in the target, when the return is:
Intent DATA = new data ();
Data. putextra ("MSG", "My message ");
Setresult (result_ OK, data );
Finish ();
Data/information returned from testbundle:
@ Override
Protected void onactivityresult (INT requestcode, int resultcode, intent data ){
String MSG = data. getextras. getstring ("MSG ");
//...
}