"Android UI Design and development" 3. Boot interface (iii) implement the application to launch only one boot interface

Source: Internet
Author: User

Most of the Guide interface is basically a uniform, as long as the mastery of a, basically there is nothing to say, to realize that the application only launches a boot interface such effects, as long as the use of Sharedpreferences class, will make the program very simple, Here is a detailed introduction to how this class is used

Detailed introduction and usage of 1.SharedPreferences

In fact, in 20. Game Development Foundation (game data storage) has been introduced, in order to complete the article or to introduce again.

Do software development should know, a lot of software will have configuration files, which is stored in the program running the various property values, because of its configuration information is not much, if the use of database to store is not cost-effective, because the database connection and operation time greatly affected the efficiency of the program, So we use the corresponding relationship of the key value to store these configuration information. Sharedpreferences is the technology used in Android to implement this storage method.

The sharedpreferences is simple to use and can easily store data and read data. Sharedpreferences can save only simple types of data, such as String, int, and so on. It is common to convert data of complex types to Base64 encoding, then save the converted data as a string in an XML file, and then save it with Sharedpreferences.

Sharedpreferences How to use:
<1> using the Getsharedpreferences method of the activity class to get the Sharedpreferences object, The name of the file where the key-value is stored is specified by the first parameter of the Getsharedpreferences method;
<2> using Sharedpreferences interface to obtain Sharedpreferences.editor object;
<3> Save the Key-value pair via the Putxxx method of the Sharedpreferences.editor interface. where xxx represents a different data type. For example: The value of a string type requires the Putstring method;
<4> Save the Key-value pair via the commit method of the Sharedpreferences.editor interface. The Commit method is equivalent to a commit operation in a database transaction.

The writing process for the specific code is:


A, storage data information
<1> Open preferences, name setting, open it if it exists, or create a new preferences

<2> let setting in edit state

Sharedpreferences.editor Editor = Settings.edit ();

<3> Store Data

Editor.putstring ("name", "Cnblogs"); Editor.putstring ("URL", "www.cnblogs.com");

<4> Complete Submission

Editor.commit ();


B, read the data information
<1> Get Preferences

Sharedpreferences settings = getsharedpreferences ("setting", 0);

<2> Extracting data

String name == setting.getstring ("URL", "default");


This is how sharedpreferences is used, where the preferences file location you create can be viewed in eclipse:
Ddms->file Explorer/data/data/<package Name>/shared_prefs/setting.xml

2. Implementation (Images are welcome interface, Guide circle, Software homepage)
First Launch program: Welcome interface------------Software homepage
Start the program later: Welcome screen--Software home

3. Specific implementation code

(1) Welcome to the page Java code, is simple to build a thread, delay the specified time, and then jump on it

 PackageCom.yanis.ui;Importandroid.app.Activity;ImportAndroid.content.Context;Importandroid.content.Intent;Importandroid.content.SharedPreferences;ImportAndroid.os.Bundle; Public classWelcomeactivityextendsActivityImplementsRunnable { Public Static Final intVERSION = 1;  Public StaticSharedpreferences sp; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_welcome); //Start a deferred thread        NewThread ( This). Start (); } @Override Public voidrun () {Try {            //Two seconds delay timeThread.Sleep (2000); //read the data needed in the SharedpreferencesSP = getsharedpreferences ("y_setting", context.mode_private); /*** If the user is not the first time to use the direct switch to the display interface, or switch to the boot interface*/            if(Sp.getint ("VERSION", 0)! =VERSION) {StartActivity (NewIntent (welcomeactivity. This, guideactivity.class)); } Else{startactivity (NewIntent (welcomeactivity. This, mainactivity.class));        } finish (); } Catch(Exception e) {} }}
welcomeactivity

(2) Guide the page, with the Viewpager implementation, you can refer to the following Viewpager introduction and simple implementation , specific can be viewed in the source code

(3) Homepage, this is nothing to say, just a page showing the layout.

Source code Address: https://github.com/YeXiaoChao/Yc_ui_guideview_once

Source: http://blog.csdn.net/yangyu20121224/article/details/8987342

"Android UI Design and development" 3. Boot interface (iii) implement the application to launch only one boot interface

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.