The android device connects to Bluetooth peripherals and causes the activity recreate problem.

Source: Internet
Author: User

Recently encountered a bug. After android connects to the bluetooth device, the program unexpectedly exits (only on some nexus devices ).

I found an error at the JNI layer from logcat (my program uses JNI ),

The onDestroy of the activity is called.

This is easy to handle. It must be because the configChange is triggered after the device is connected, and the program does not properly handle this situation.

Check AndroidManifest. xml and find that the configChanges attribute of the activity is


[Plain]
Android: configChanges = "fontScale | keyboard | keyboardHidden | locale | orientation | screenLayout | uiMode | screenSize"

Android: configChanges = "fontScale | keyboard | keyboardHidden | locale | orientation | screenLayout | uiMode | screenSize" contains almost all configChanges, except for mcc, mnc, touchscreen, navigation, smallestScreenSize and layoutDirection.

Here, mcc and mnc cannot be changed theoretically, because I have not moved to the ground;

Touchscreen and navigation are both marked as "This shoshould never normally happen" in the android doc, so they are not considered for the time being;

SmallestScreenSize and layoutDirection are neither theoretically possible.

However, in addition to configChanges which causes the activity to restart, it is impossible to think of other possibilities.

Therefore, the configchanges are added one by one for troubleshooting, and the result is navigation.

Recall that I am connected to a Bluetooth keyboard, which does change the type of navigation.

After connecting to the Bluetooth keyboard, I can use the direction key to navigate.

This is a rare opportunity for people to gain insights and make documents untrusted (especially for android documents ).

However, this problem only occurs on some nexus devices at hand,

It is understandable that, after all, the device is positioned there.

However, considering the penetration rate of nexus devices, the fragmentation problem still persists.

 

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.