Android Note 2-Test and data storage methods under Android, Android Data Storage

Source: Internet
Author: User
Tags xml parser

Android Note 2-Test and data storage methods under Android, Android Data Storage

Today, I will introduce another basic knowledge of Android, the testing and data storage methods under android.
Then, send the corresponding notes synchronously. Old Rules: Use a picture to introduce today's content.
If you cannot see the image clearly, right-click it and open it in a new window.

I. Test 1. Classification

Black box test: This test is performed based on the correspondence between input and output data from the user's perspective.
  
White-box testing: Also known as structure testing, transparent box testing, logic-driven testing, or code-based testing.
  
Unit test: module test is a short piece of code written by developers to check whether a very small and clear function of the tested code is correct.
  
Function Testing: tests the features and operational behaviors of a product based on product features, operation descriptions, and user solutions to determine whether they meet the design requirements.
  
Stress testing: the subject assigns a certain number of tasks and jobs to the observer to observe the individual's completion of the task.
  
Integration Test: logical extension of unit test. The simplest form is that two tested units are combined into one component and the interfaces between them are tested.

2. Unit Test Framework (Junit)

Android code can only run in the Dalvik virtual machine on the mobile phone. An error is reported in the JVM of the PC. Write the test case and upload the test code to the Android mobile phone or simulator to run it.

3. unit test process in Android

1. Write the business logic code

2. Write test cases. A Class inherits AndroidTestCase.

3. Write the test method public void testAdd () throws Exception.

4. Configuration list file
Add instrumention under the mainfest node,
Add uses-library under the application Node

4. Introduction to logcat in Android
Log. v: verbose prompts black
Log. d: debug blue
Log. I: info reminder green
Log. w: warn warning orange
Log. e: error red

Ii. Android file storage 1. Save data to SD Card 1 and obtain the external SD card directory:
      Environment.getExternalStorageDirectory()
2. Obtain the Mount status:
      Environment.getExternalStorageState()
3. Obtain the remaining sd space:
          Environment.getExternalStorageDirectory().getUsableSpace();
2. Save data to an internal storage device (/data/package name /)

Private application folder. By default, other applications cannot access it. This ensures data security.

Context. getFilesDir () =/data/package name/files user file directory
Context. getCacheDir () =/data/package name/cache directory

3. Android permission Mechanism

MODE_PRIVATE private file
MODE_WORLD_READABLE
MODE_WORLD_WRITEABLE: globally writable file
MODE_WORLD_READABLE + MODE_WORLD_WRITEABLE globally readable and writable

Iv. Android XML data access (pull parser) 1. xml data parsing
A. create xml parser XmlPullParser parser = Xml. newPullParser (); B. initialize the xml parser to specify which stream to parse and which encoding to parse parser. setInput (is, "UTF-8"); c. parse xml data while (type! = XmlPullParser. END_DOCUMENT) {// until the end of the document // read data... type = parser. next (); // to the next} d. Close the data stream
2. xml creation (serialization)
A. create Xml serializer = Xml. newSerializer (); B. initialize the xml serializer, set the output stream, and specify the serialize set serializer. setOutput (fos, "UTF-8"); c. write xml data // the beginning of the document serializer. startDocument ("UTF-8", true); serializer. startTag (null, "info"); serializer. startTag (null, "qq"); serializer. text (qq); serializer. endTag (null, "qq"); serializer. startTag (null, "pwd"); serializer. text (pwd); serializer. endTag (null, "pwd"); serializer. endTag (null, "info"); // end of the Document serializer. endDocument (); d. fos. close ();
V. SharedPreference

Storage location:/data/package name/shared_prefs/xxx. xml

1. Write Data
Initialize SharedPreferences sp = this. getSharedPreferences ("config", MODE_PRIVATE); get Editor editor Editor = sp through SharedPreferences. edit (); write data editor. putString ("qq", qq); editor. putString ("pwd", pwd); editor. putBoolean ("isChecked", isChecked); Submit the data editor. commit ();
2. Read data
// 1. initialize SharedPreferences sp = this. getSharedPreferences ("config", MODE_PRIVATE); // 2. read data and set the data String qq = sp. getString ("qq", ""); boolean isChecked = sp. getBoolean ("isChecked", false );

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.