Discussion on the compatibility of open source libraries during the use of Android

Source: Internet
Author: User
Tags integer

1, in the Android4.0 environment compiled Actionbarsherlock, Slidingmenu class library, can not be used in the version below 4.0

I believe many people, like me, assume that applications compiled in a lower version (such as Android2.1 or version 2.3) can run in a higher version, but applications compiled in a high version (such as Android3.0 or 4.0) may not run in a lower version. As a result, we might try to change some of the code compiled in the high version into a lower version of the Android SDK to be compatible. We have been ignoring the statements about compatibility in <manifest> files, such as the following code snippet.

<USES-SDK 
android:minsdkversion= "integer"         
android:targetsdkversion= "integer"         
android: maxsdkversion= "integer"
    
 />

Android:minsdkversion declared that the application could run on the smallest API version. How do we know what API an application can run on? Changcha Android Reference (API documentation) should be familiar with the following picture.

The API reference not only describes the function of the function you call, but also describes what version of the API it was introduced in (see Red Box). So we need to examine what version of the API is introduced in the system call function in our application.

Slidingmenu's compatibility statement

Actionbarsherlock's compatibility statement

The above two pictures are the slidingmenu, actionbarsherlock compatibility instructions respectively. If we only use Slidingmenu, then the compatibility instructions in our application Android:minsdkversion as long as more than 5, if you use Slidingmenu, Actionbarsherlock, then Android : Minsdkversion must be at least 7.

For the SDK introduced in the Android version, Google will generally introduce the appropriate compatibility packs. For example, the fragment API introduced in Android3.0, in ANDROID-SUPPORT-V4 This compatibility package has the corresponding compatible API, see Create fragment.

Finally, make a conclusion that in a high version of the environment (such as Android4.0) the application of the compiler can not run in the lower version of the Android system is not to see the compiled SDK version, but depends on the android:minsdkversion the minimum API version of the declaration.

Of course, you can't declare that android:minsdkversion is 5, and the result is an API that was introduced in the reference using Android:minsdkversion 11.

2. Encounter "Illegalstateexception:both Setbehindcontentview must be called in OnCreate, addition to Setcontentview." Error

This error is a bug that pops up when you start and don't see the interface. This is because there is a lack of setbehindcontentview (r.layout.menu_frame) in the code. And this function is mainly used to determine what the sidebar looks like.

public class Baseactivity extends slidingfragmentactivity

And that's because my activity inherits Slidingfragmentactivity (see Code snippet below), and this particular activity itself has a sidebar, Therefore, you must call the Setbehindcontentview () function at the OnCreate function to set the style of the sidebar.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.