First you have to have a class to inherit the application class, and override the OnCreate method, which is the entry for the Android program.
In order for all classes to be able to use the parameters inside, this class is instantiated.
In order to store a large amount of data we can define a HashMap collection and give the map a get method.
private static Oneapplication OA;
Private hashmap<string,object> map = new hashmap<string, object> ();
public static oneapplication Getoa ()
{
return OA;
}
public void OnCreate ()
{
Super.oncreate ();
This.oa = this;
}
The value is stored in the first activity,
Intent Intent = new Intent (mainactivity.this,twoactivity.class);
Oneapplication one = Oneapplication.getoa ();
One.getmap (). put ("haha", "haha");
One.getmap (). Put ("King eight Eggs", "Wangba");
StartActivity (Intent);
Take a value in the second activity and remove them in the same way as before, to facilitate garbage collection!
Oneapplication one = Oneapplication.getoa ();
protected void OnCreate (Bundle savedinstancestate)
{
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_two);
LOG.D ("Twoactivity", (String) One.getmap (). Get ("haha"));
LOG.D ("Twoactivity", (String) One.getmap (). Get ("King Eight Egg"));
}
protected void OnDestroy ()
{
Super.ondestroy ();
One.getmap (). Remove ("haha");
One.getmap (). Remove ("King eight Eggs");
}
Aolication Global Pass Parameters