The example in this article describes how Android programming enables you to share data between two activity and access each other. Share to everyone for your reference, specific as follows:
I've turned from Windows programming to learning about Android, and I've been thinking that if two of the activity can be like a C # or a form in Delphi, you have direct access to its members (characters, numbers, member objects, and so on), and you can call its exposed methods, That should be more convenient than using intent to transmit data, and then try the following methods, the test is basically no problem, sent to everyone to discuss. I learn Android soon, naïve place hope everybody don't laugh
Principle: Suppose there are two Activity:activitymain and activitynew, start activitynew in Activitymain, and in activitynew you can access the member objects in the Activitymain. Invokes the method that it exposes. Then define a static member variable in Activitymain, type Activitymain, and then in the OnCreate process, assign the Activitymain instance this to the member:
public class Activitymain extends activity {public
static activitymain mainact;//define a member variable of this type
String getstr () { return
"Shao Jian";
}
@Override public
void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.main);
Mainact = this; Here, assign this instance to a static member variable
}
...
}
To access the member variables and methods in Activitymain in Activitynew:
public class Activitynew extends activity {
@Override
protected void onCreate (Bundle savedinstancestate) {
String title = bundle.getstring ("title");
title = MainActicivity.MainAct.GetStr (); Invoke member Method
T.settext (Title.trim ());
Super.oncreate (savedinstancestate);
}
I hope this article will help you with the Android program.