Support for versions earlier than 2.0 in android

Source: Internet
Author: User

 

Recently I wrote a mini game for android2.2. After I put it on google market, I found that some versions of Android 1.5 and Android 1.6 were downloaded. I put it on the simulator and found that none of them can be started. I checked the website for half a day and finally solved the problem. Write down and keep a record.

1. Modify the response method of the BACK key.

Before 2.0, the BACK key responds in onKeyDown.

After 2.0, the BACK key responds in onBackPressed.

To support systems earlier than 2.0, a function is directly added. A better way is to create a common parent class on top of all your own activities. In this case, it will be easier to modify.

Public boolean onKeyDown (int keyCode, KeyEvent event ){

// Back key

If (keyCode = KeyEvent. KEYCODE_BACK ){

OnBackPressed ();

}

Return super. onKeyDown (keyCode, event );

}

Note: Do not add the [@ Override] Comment on the onBackPressed method.

 

2. Modify the attribute value of filling the parent region in layout.

Before 2.0, It is fill_parent

Fill_parent and match_parent are supported after 2.0

So I renamed all of them [fill_parent].

 

3. Exception at startup

After the preceding two points are reached, the following exception will still be reported during startup in 1.5.

ERROR/AndroidRuntime (803): Caused by: java. io. FileNotFoundException: res/drawable/title_bar_shadow.9.png

It turns out that you only need to directly create a drawable directory under res and then test the required images. Upgrade title_bar_shadow.9.png.

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.