simple use of intent transfer data in android:
1. Pass data using intent:
first put the data that needs to be passed into the intent
Intent Intent = new Intent (mainactivity.this,otheractivity.class);
Intent.putextra ("name", " passing Data using intent");
StartActivity (Intent);
then receive the data in the target activity:
Intent intent=getintent ();
Intent.getstringextra ("name")// Get Data
2. use intent to pass static variables:
a static variable is set in the target activity, the data is stored in a static variable when the target activity is started, and then read directly in the target activity.
Intent Intent = new Intent (Mainactivity.this,
Other2activity.class);
Other2activity.data = " pass static variable with intent";
StartActivity (Intent);
3. passing global variables using intent
New Class MYAPP Inherits application, specifying the Name property of the application node in the Androidmanifest.xml file as MYAPP (android:name= ". MyApp ")
public class MyApp extends application {
Publicstring data;
Publicstring GetData () {return data; }
Public Voidsetdata (String data) {This.data =data; }
@Override public void OnCreate () {
Super.oncreate ();
SetData ("Hello World");
} }
}
writes data to the global variable when the target activity is started :
Intent Intent = new Intent (mainactivity.this,other3activity.class);
MyApp MyApp = (MyApp) getapplication ();
Myapp.setdata (" use intent to pass global Variables ");
StartActivity (Intent);
To receive data in the target activity:
MyApp myapp= (MyApp) getapplication ();
Myapp.getdata ();
4. using the Clipboard to pass data
Write the data that you want to pass to the Clipboard:
Intent Intent =new Intent (Mainactivity.this,
Clipboardactivity.class);
Clipboardmanagerclipboardmanager= (Clipboardmanager) Getsystemservice (MainActivity.this.CLIPBOARD_SERVICE);
Clipboardmanager.settext (" using the Clipboard to transmit data ");
StartActivity (Intent);
and then in the target Activity value in:
Clipboardmanager clipboardmanager= (Clipboardmanager) Getsystemservice (Clipboardactivity.clipboard_service);
Clipboardmanager.gettext ();
above is some simple activity data transfer. Besides, I'm at the end of the development app will use some app test the online automated test tool: www.ineice.com
Use intent to pass data between activity in Android