It blue Leopard Highly recommended: In line with 1-2 years of work experience, development difficulties and related optimization:

Source: Internet
Author: User


It blue Leopard Highly recommended: In line with 1-2 years of work experience, development difficulties and related optimization:

it Blue Panther

------------------> SQLite database Version upgrade

1.sqlite Upgrade steps:

1. Write yourself a class inheriting from Sqliteopenhelper

2. The two methods that will implement Sqliteopenhelper OnCreate and Onupgrade,google document two callback methods are interpreted when the database is created to call and update the version of the database when called

3.Sqlite database is mainly used to cache the data of the application, but the application is always in the update version, the corresponding data table field will always increase will change or reduce

4. This time you need to control the version of the database, because the fields in the SQLite database assume that the new version of the Application design table is 10 fields, and the cache is only 9 fields cached before the query database column

Then the value will appear null pointer exception or error

5. So the version of the SQLite database is introduced into Android so that the old database of the application can be compatible with the new version of the database.

6. In order to be compatible with the previous version of the database, simply add a field or delete the field when the app's version is updated

7. Your development program is currently a 1.0.0 version, the program uses the database, but after the iteration of the version to 1.0.1, a table of the database added a field in the software 1.0.1 version of the need to upgrade

8. Database upgrade can be used in order to allow the old data can not be lost, so can not delete all the data in the previous database, then need to have a place to detect changes in the version, this with Android app upgrade is a reason

Of course, this test is in the Onupgrade method of Sqliteopenhelper.


2. What should I pay attention to in database upgrade?

When the 1.0 version of the software is upgraded to version 1.1, the old data cannot be lost. Then in the 1.1 version of the program will have a place to detect the new software version with the old
The database is incompatible and there is a way to upgrade the database of 1.0 software to a database that can be used by the 1.1 software. In other words, add that field to the table in the database of the 1.0 software and give the field the default value.


3. How does the program know that the database needs to be upgraded?

The constructor for the Sqliteopenhelper class has a parameter of int version, which means the database version number. For example, in software version 1.0, when we use Sqliteopenhelper to access the database,

This parameter is 1, then the database version number 1 will be written in our database.

By the 1.1 version, our database needs to change, then our 1.1 version of the program will use an integer greater than 1 to construct the Sqliteopenhelper class, to access the new database, such as 2.

When our 1.1 new program reads the 1.0 version of the old database, we find that the database version stored in the old database is 1, and when our new program accesses it with a version number of 2, the system knows that the database needs to be upgraded.

-----------------Android version adaptation (how to compatible with 4.3-2.3 version)

For example, the product design wants some more than 4.3 new effects, but how to be compatible with 4.3-2.3 user groups,
The premise is that we apk on the Friend League data shows that 4.3-2.3 occupies 25% of the user community.
In this regard, our current practice is that the new design of the page to use the new effects, according to the phone version number to judge,
If it is a lower version of the phone and most of the new effects are not compatible we show the old page.


-----------------"an apk how to quickly and easily play multiple different package names of products (multi-channel multiple product promotion)

Our market in the promotion of the apk sometimes need to be based on the channel to play the different package name apk and these apk style and content display and text show slightly different.
What we are doing now is to link the main project as a Libs form to the project that you want to package, so that it is convenient to make a different package name, create a project directly,
Link the main project, and then you can modify some of the new projects, such as the title style, the first page to enter the style
(because we've made several sets of pages to determine which style you're going by depending on the type), a new apk appears.

------------------"Android adaptation

Adaptation is also a headache, at the end of last year we began to be 720 for the mainstream to do the adaptation, detailed matching Baidu
There are other interviewers who will ask you if your designer is out of the picture, based on the iOS out or Android.
There are several answers,
(1) Directly according to the image of Android to do a set of 720*1280
(2) According to the iOS plot
It is well known that the pixel size of iOS design is 640*960/1136,android mainstream hdpi mode pixel size is 480*800. ,
Their conversion relationship is that 75% of the iOS pixel size is the pixel size of Android

Approximate algorithm, we can look at:
In fact, after the entire process, we have come to a simpler conversion relationship: iOS pixel size *75%=android pixel size,
The size of the *2/3=android for Android pixel size. The result: the size of the *75%*2/3=android for iOS pixel size.
So, in iOS a wide 600px thing, in the Android hdpi mode, just 300DP, exactly 50%, very easy to count, right?

To put it simply:
I. About layout adaptation

1. Do not use absolute layout

2, try to use match_parent instead of fill_parent.

3, can use the heavy place as far as possible to use the weight (android:layout_weight)

4, if it is a solid color background, try to use the shape of Android to customize.

5. If you need to fit at a specific resolution, you can create a new Layout-hxw.xml folder on the Res directory. For example, to fit a 1080*1800 screen.

(Meizu MX3 uses this resolution) creates a new Layout-1800x1080.xml folder and then defines the layout below. The Android system will prioritize

Look for layouts with the same resolution and, if they don't exist, use the default layout under layouts.

Reprint please Masaaki Source: It blue Leopard Android effects


It blue Leopard Highly recommended: In line with 1-2 years of work experience, development difficulties and related optimization:

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.