ANDROID_ file Storage

Source: Internet
Author: User

Because of the needs of the project, want to implement a guide to use the Welcome page effect, through the online inquiry, a solution is to be implemented through the Sharedpreferences file storage method, the specific implementation is similar to the first time to obtain the data in the Sharedpreferences, If the data does not exist, it will return the default value, the specific code implementation, immediately served.

Mainactivity 's code:

public class Mainactivity extends Activity {public Boolean flag = False;public TextView textview;public String file_name= " Sharedpreferences ";//The unique identification of the stored data @overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); TextView = (TextView) Findviewbyid (R.id.textview); init ();} public void init () {/* * * file storage in Android, the default data will be returned if data is not stored for the first time */sharedpreferences sharedpreferences = Getsharedpreferences (file_name, context.mode_private);//Gets the saved data from the file string usernamecontent = Sharedpreferences.getstring ("username", "default data"); Textview.settext (usernamecontent);/*sharedpreferences sp = Getsharedpreferences (file_name, context.mode_private); Editor editor = Sp.edit (); Editor.clear (); editor.putstring ("name", "normal data"); Editor.commit (); String name = sp.getstring ("name", "Default data"), Textview.settext (name), */}}

Believe that through this code, you will be able to have a detailed understanding of the sharedpreferences storage.

------------If there is a mistake, but also look at a lot of advice-------------

ANDROID_ file Storage

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.