Resolve Android access technical issues

Source: Internet
Author: User

In Android, there are several data storage methods, such as file storage and file database storage. Android comes with an SQLite database, embedded developers are not familiar with this cross-platform local file database.

In Android, a new method is proposed for data access. The ContentProvider method is similar to the ContentProvider method of MS, OLEDB, and ODBC unified data mode. First, let's take a look at the use of SQLite in Android. The simplest way to use it in Android is to use openorCreateDatabase of the Context object. Let's take a look at a piece of code:

 
 
  1. Private String getName ()
  2. {
  3. String name = null;
  4. Cursor cur = this. getContentResolver (). query (ProviderConst. MY_TEST_URI, new String [] {"id", "name"}, null );
  5. If (cur = null)
  6. Return null;
  7. Cur. moveToFirst ();
  8. Do
  9. {
  10. Namename = name + cur. getString (1) + "\ n ";
  11. } While (cur. moveToNext ());
  12. Return name;
  13. }
  14. We can also use:
  15. Private String getName ()
  16. {
  17. String name = null;
  18. Cursor cur = this. managedQuery (ProviderConst. MY_TEST_URI, new String [] {"id", "name"}, null );
  19. If (cur = null)
  20. Return null;
  21. Cur. moveToFirst ();
  22. Do
  23. {
  24. Namename = name + cur. getString (1) + "\ n ";
  25. } While (cur. moveToNext ());
  26. Return name;
  27. }

We have understood the simple usage method, so let's analyze the complicated content.

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.