3

Android mobile app always get restarted once it is connected or disconnected to bluetooth device. what something else i need to comment ? tell me.

Sidle Ciel
  • 39
  • 1
  • 3
  • You don't need to comment anything. But it would help you to take a look at your logcat and see what crashes, if it crashes. We can't guess what you did wrong, but you must have done something wrong as many other bluetooth apps work just fine. – 323go Jun 24 '15 at 16:40
  • show your code that crashes – joel goldstick Jun 24 '15 at 16:51
  • ok, i got the same problem. following is the link http://stackoverflow.com/questions/25734849/android-mobile-app-always-get-restarted-once-it-is-connected-or-disconnected-to – Sidle Ciel Jun 24 '15 at 17:11
  • Hi,@323go . i still go wrong. according above solution. you can see youtube, has same situation. – Sidle Ciel Jun 25 '15 at 02:31
  • Hi @SidleCiel can you find solution for this issue.. ? – kumar Sudheer Dec 01 '16 at 15:58

2 Answers2

12

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:

Community
  • 1
  • 1
iszlavik
  • 121
  • 1
  • 4
1

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.

g_codex
  • 25
  • 6