Android Development Series logs-(2)

Source: Internet
Author: User

I. JUnit
1. What is JUnit?
JUnit is a testing method. When writing a business method, we 'd better test it to ensure that this method can run normally under various circumstances.
2. How to Use JUnit
Configure androidmanifest. xml
Configure the <instrumentation> node under the <manifest> node to specify the test class and project to be tested.
Configure the <uses-library> node under the <applicaiton> node to specify the class library used
Define the test class to inherit from androidtestcase, and write the test method.
The test method starts with "test" in lowercase.
Right-click Run as androidtestcase
Click a blank space to run all methods starting with "test" in lower case.
You can click a method name to run a specified method.

Ii. Read and Write files
1. Write SD card
You need to configure the permission to write the SD card <uses-Permission Android: Name = "android. Permission. write_external_storage"/>
Use the environment. getexternalstoragedirectory () method to obtain the path of the SD card. compatible with All Versions
Use environment. getexternalstoragestate (). Equals (environment. media_mounted) to determine whether the SD card is available
2. Write mobile phone
Use context. openfileoutput () to open the output stream
Permission can be specified, mode_private, mode_world_readable, mode_world_writeable

Iii. sharedpreferences
1. Write
Call the Edit () method to obtain the editor object.
Call methods such as putstring () and putint () to save data.
Modify the Commit () method
2. Read
Read data using the getstring () and getint () methods.

Iv. xml
1. Resolution
Xmlpullparser
Setinput ()
Geteventtype ()
Next ()
Getname ()
Getattributevalue ()
Nexttext ()
2. Generate
Xmlserializer
Startdocument ()
Enddocument ()
Starttag ()
Endtag ()
Attribute ()
Text ()

5. SQLite
Features: data types are not differentiated. They are built directly on mobile phones and are small.

1. create a database
define a class that inherits sqliteopenhelper, define a constructor that calls the four parameters of the parent class, and override two Abstract METHODS: oncreate (), onupgrade ()
call the getwriteabledatabase () method of the custom class to obtain the database object.
the first execution has no database file in the specified environment: Create a database and run oncreate () method
run later, the database exists, and the version number does not change: only open the database
the database exists, the version number changes: Open the database, and execute the onupgrade () method
2. add, delete, modify, and delete methods
after obtaining the sqlitedatabase object, call the execsql () method to execute the SQL statement.
3. query Method
after obtaining the sqlitedatabase object, call the rawquery () method to query and obtain the cursor.
use the movetonext () method to move the cursor and call getstring (), getint () and other methods to obtain data

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.