How to Use the STL library and androidstl in android apps

Source: Internet
Author: User

How to Use the STL library and androidstl in android apps

Method:

1. Create Application. mk in the jni directory; replace the value on the Right of APP_STL: = stlport_static with the following values:

System-use the default minimum C ++ Runtime Library. In this way, the generated application is small in size and memory usage is small, but some functions cannot be supported.

Stlport_static-use STLport as the static library, which is highly recommended by Android Development Network.

Stlport_shared-STLport is used as a dynamic library, which may generate compatibility and some earlier Android firmware versions. It is not recommended currently.

Gnustl_static-use GNU libstdc ++ as the static library

 

By default, STLPORT does not support C ++ Exception Handling and RTTI, so do not use-fexceptions or-frtti. If necessary, you can use gnustl_static to support the features of Standard C ++, however, the size of the generated file will be too large and the running efficiency will be lower.

Supports C ++ Exception Handling in Application. add LOCAL_CPPFLAGS + =-fexceptions to mk. If RTTI is supported in the same way, add LOCAL_CPPFLAGS + =-frtti. Here we will remind you again that the second article uses the gnustl static library instead of stlport.

Force re-compile STLPort, and add STLPORT_FORCE_REBUILD: = true to Application. mk to force re-compile the STLPort source code. for some reasons, you may need to modify the STLPort library.

2. include related header files in the cpp file to use STL and use using namespace std;



How does the android app obtain the required data from the database? Android automatically provides a database. Android apps use SQLite and must create their own databases to create tables and index data. Android provides SQLiteOpenHelper to help create databases. As long as the SQLiteOpenHelper class inherits the SQLiteOpenHelper class, it is easy to create databases. it encapsulates at least three methods to create and update a database using the logic SQLiteOpenHelper subclass:
The constructor calls the SQLiteOpenHelper constructor of the parent class.
OnCreate () method; // TODO
OnUpgrage () method // TODO operation to change the database version
After the database operation is completed (for example, the Activity has been closed), you need to call the SQLiteDatabase Close () method to release the database connection.
Database Operations best practices create a helper class contact Module
Class ContactsDatabaseHelper extends SQLiteOpenHelper
3.2 Cursor class
Android uses the Cursor class to return the required value. The Cursor class is used as a pointer to query and return from the database. The Cursor class allows Android to manage rows and columns more effectively. The ContentValues object storage key/value pair put () is used () method To Insert key values of the same data type
3.3 Data Type
SQLite and its database are consistent with each other for data types. When creating a TABLE, the create table statement specifies a column data type and puts any data type into any column. When a value is inserted into the database, SQLite checks whether this type and associated column are of the same type. if the matching result is true, SQLite will try to convert the value to the column type that can be converted, then the value will be compared to the String) in the INTEGER column, SQLite is called the weak type (manifest typing .)

Iv. Database Operations
4.1 create and open a database
Android uses the openOrCreateDatabase method to create and open databases. Because no data inventory is detected automatically, the database is created when the database is opened. If the database is created successfully, the SQLiteDatebase object is returned. Otherwise, an exception is thrown. FileNotFoundException
Next we will create a database named Test and return the SQLiteDatabase object mSQLiteDatabase
MSQLiteDatabase = this. openOrCreateDatabase ("Test", MODE_PRIVATE, null );

4.2 create a table
ExecSQL statements
String CREATE_TABLE = "create table name (column name ......) ";
MSQLiteDatabase.exe cSQL (CREATE_TABLE );

When creating a table, always determine the 64-bit integer alias of the primary key field _ rowid. The feature auto-growth function searches for unused values of this field when the primary key field reaches the limit (some records are deleted _ rowid will be recycled) the keyword autoincrement must be added to the auto-primary key to strictly increase
4.3 Delete a table
MSQLiteDatabase ("drop table name ");
How to Choose android app development mode Web applications access through mobile browsers directly using HTML5 to access some basic mobile phone functions development and maintenance are very simple hybrid apps combined with the previous two application architecture is equivalent to Web the complexity of encapsulating the local app shell is between the previous two. There is a special framework between them to complete the sample work, such as phonegap and other web development frameworks. What should we choose? In fact, the principle is simple: familiar with technology development: to use existing knowledge to a large extent, although you need to learn new things, there is no approval process required: to develop an app, you need to release the app store for approval, while web is automatically upgraded when you only need the app Publishing Server. Web applications allow users to access the new app version without manual upgrades. Most devices are supported: standard Technology example HTML5 most smart phones support agile development: no approval is required to support rapid development of multiple devices. New features are provided to users as soon as possible.

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.