Android: screen rotation, on destroy and services connundrum

后端 未结 3 757
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 16:12

I\'ve modified the bluetooth chat example from the SDK demos to be able to control an arduino powered bluetooth LED matrix. Using the chat program, I can send messages to the

3条回答
  •  执念已碎
    2021-01-21 16:47

    If you add "android:configChanges="orientation"" into your Manifest to prevent the activity from being destroyed and re-created, you might want to implement the method:

    public void onConfigurationChanged(Configuration newConfig)
    

    This method is executed every time the system configuration is changed, i.e. when you rotate the phone and orientation is changed. Inside this method you can re-apply a new layout for your activity:

    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Log.e(TAG, "ORIENTATION_LANDSCAPE");
        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            Log.e(TAG, "ORIENTATION_PORTRAIT");
        }
    }
    

提交回复
热议问题