In Android development, SQLite is used to realize the functions of news collection and canceling collection

Before learning Oracle, I simply thought that the database only exists on the server side. After learning Android, I found that Android and IOS themselves "carry" the database SQLite. It is a lightweight, embedded and relational database. It is a widely used database system such as Android and IOS. Used to store the status of the local. Just write out a function to realize news collection. Write it out for your reference.

In Android, we operate SQLite database through the object of sqlitedatabase class. Because SQLite database does not need to establish connection and authentication like C / s database, and the characteristics of SQLite database single file database, obtaining sqlitedatabase object is as simple as obtaining operation file object.

SQLite needs to create database, create table, and then add, delete, modify and query. So the first step is to create a database. Sqliteopenhelper is an abstract class to manage database creation and version management. To use it, you must implement its ncreate (sqlitedatabase), onupgrade (sqlitedatabase, int, int) methods

Android provides a class called sqlitedatabase, which encapsulates some APIs for operating the database. Basic CRUD operations can be realized by using it. Database instances can be obtained through getwritabledatabase() and getreadabledatabase(), and some Dao layer methods can be written to operate tables:

Use actionbar to make the menu button, click collect, and execute the code:

The above is what Xiaobian introduced to you. In Android development, SQLite is used to realize the functions of news collection and canceling collection. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

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
分享
二维码
< <上一篇
下一篇>>