Questions about using global variables for Android

Source: Internet
Author: User

Now every day is busy, and a busy, put the writing notes in the back, recently in the writing process, suddenly to use global variables, in accordance with the previous way, wrote a class, and then the variables are declared as static variables, and then used as a global variable, but in the event of activity switching, Suddenly found that in the previous acitivty in the assignment, but in the back but can not get to, just beginning to think there are other places have problems, but later check found also no problem, this problem troubled for one hours, and then another way of writing, is to use application, but in the use of the time , also found that there is such a problem, at that time really feel do not know how to deal with, on-line search data also did not see how to solve!

In the end I changed the initialization of a place to test, this assignment actually does not disappear, but at this time still do not understand this is why, many times test, suddenly think of a problem, because I in these two activity used a different end way, one for system.exit (0); One for Finishi (); the feeling may have been caused by these two ways, and later tested, indeed, by these two methods, If the use of System.exit (0), the way, is equal to the end of the acitvity, so that his operation of the data will no longer exist, the system may think that there is no need to use the Finishi (), the words, although the exit, but this is not the release of resources , just push the current activity to the background, no longer show, but he does not release resources, when the specific resources released, determined by the system, Of course system.exit (0); This form is not really an exit system, because we may have other activity running, but he did release the resources! This is why, not quite understand!

To the problem basically solved, but there is a problem, so for example, I login interface, after the login is completed, in fact, there is no use, I would like to use exit, how to put his login after the user name, password to save it? This time, think of intent this, pass value, use intent to pass the value passed, then receive, upload to the main page of the display, and the main page, only when the system exits will call exit, so, this in the initialization of public variables, it is possible.

Questions about using global variables for Android

Related Article

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.