Implementation of Android UI design and development application only starts the boot interface once

This article is the end of the whole guide interface development topic. I think most of the guide interfaces are basically the same. As long as I master one, there is basically nothing to say. If I encounter a better and more interesting guide interface in future development, the blogger will share it with you in time, Today's content is mainly to teach you that the application only displays the boot interface when it is started for the first time, and will not be displayed when it is started in the future.

In fact, if you want to achieve this effect, you can make the program very simple by using the SharedPreferences class. Let's introduce the use of this class in detail

1、 Detailed introduction and usage of SharedPreferences

SharedPreferences introduction:

As we all know in software development, many software will have configuration files to store the attribute values during the operation of the program. Because there is not much configuration information, it is not cost-effective to use the database to store it, because the time-consuming of database connection and operation greatly affects the efficiency of the program, Therefore, we use the one-to-one correspondence of key values to store these configuration information. Shared preferences is the technology used to implement this storage method in Android.

SharedPreferences is very simple to use and can easily store and read data. SharedPreferences can only save simple types of data, such as string, int, and so on. Generally, complex types of data will be converted into Base64 encoding, and then the converted data will be saved in XML file in the form of string, and then saved by SharedPreferences.

How to use SharedPreferences:

<1> Use the getsharedpreferences method of the activity class to obtain the SharedPreferences object, where the name of the file storing the key value is specified by the first parameter of the getsharedpreferences method< 2> Use the edit of the SharedPreferences interface to obtain the sharedpreferences.editor object< 3> Save the key value pair through the putxxx method of the sharedpreferences.editor interface. Where XXX represents different data types. For example, putstring method is required for value of string type< 4> Save the key value pair through the commit method of the sharedpreferences.editor interface. The commit method is equivalent to a commit operation in a database transaction.

The specific code writing process is as follows:

A. Store data information

<1> Open preferences with the name setting. If it exists, open it. Otherwise, create a new preferences SharedPreferences settings = getsharedpreferences ("setting", 0)< 2> Leave settings in editing status SharedPreferences. Editor editor = settings. Edit()< 3> Store data editor.putstring ("name", "ataaw"); editor.putString(“URL”,”ATAAW.COM”); < 4> Finish submitting editor. Commit();

B. Read data information

<1> Get preferences SharedPreferences settings = getsharedpreferences ("setting", 0)< 2> Take out the data string name = settings.getstring ("name", "default value"); String url = setting.getString(“URL”,”default”);

The above is how to use SharedPreferences. The storage location of the created preferences file can be viewed in Eclipse: DDMS - > File Explorer / < package name > / shared_ prefs/setting.xml

2、 Effect diagram of implementation

Start the program for the first time: welcome interface -- > boot interface -- > main page

Later startup program: startup page -- > system home page

Renderings at first startup

Welcome interface:

Effect drawing 1 of guidance interface:

Effect drawing 2 of guidance interface:

Enter the main page:

Effect drawing of starting the program in the future

Welcome interface:

Program main page:

3、 Directory structure of program

4、 Specific implementation coding

1. Add the viewpager component and activity in the guide layout interface_ guide.xml:

2. Then in the guide_ The pictures and controls to be displayed in the guide interface are added to several layout pages such as view01.xml. Because these layout interfaces are similar, I won't post them one by one here. Students in need can download the source code and guide directly_ view01.xml:

3. Then there is the layout interface of the welcome interface, activity_ welcome:

4. Finally, the layout of the main interface, activity_ main:

5. Here, we also need to create an XML file to realize the effect of user-defined buttons. I will introduce the effect of user-defined buttons in detail in the later article. I won't repeat start here_ btn.xml:

6. Now that the layout interface has been explained, let's explain the code in detail, viewpager adapter code, viewpageradapter.java:

7. Guide interface, guideactivity.java:

8. Welcome interface activity, welcome.java:

Shared preferences is used in the welcome interface to read the user's information and judge whether it is the first time to use the program. The isfirstuse here can be changed to any type according to the needs of readers. Just add a judgment to it

9. In the main interface activity, a simple layout file is loaded here. Readers can extend this class as needed. Mainactivity.java:

The topic of the guide interface is over. Next, we will give a detailed practical explanation on the UI design of the main page. I hope you can continue to pay attention to this series of articles.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>