Aolication Global Pass Parameters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.