Reputation: 39
Android mobile app always get restarted once it is connected or disconnected to bluetooth device. what something else i need to comment ? tell me.
Upvotes: 3
Views: 3638
Reputation: 35
Resurrecting an old topic, there are some bluetooth devices that - for some unapparent reason - also make other configuration changes besides the keyboard ones. In this case, try to add in your Manifest, in the desired activity, the line:
android:configChanges="keyboard|keyboardHidden|navigation"
That might be enough!
I also recommend taking a look at https://developer.android.com/guide/topics/manifest/activity-element#config, in the subtopic android:configChanges. Listed there are all the configuration changes a device can make.
Upvotes: 1
Reputation: 141
This is by design. Android restarts (recreates) activity in case of any configuration change event to ensure app adapt to the new situation:
Handling Runtime Changes - API Guide
Bluetooth connect/disconnect is similar configuration change event like orientation change, hard or soft keyboard change.
You can avoid app restart by handling configuration change event in your app:
add android:configChanges = "keyboard|keyboardHidden"
attribute into your AndroidManifest.xml:
<activity android:name=".MyActivity"
android:configChanges="keyboard|keyboardHidden"
android:label="@string/app_name">
and implement onConfigurationChanged()
method in your activity:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
See excellent answers here:
Upvotes: 14