How to detect orientation changes, but letting the android handle them?

My problem is very similar to this: Android - ActionBar doesn't resize using onConfigurationChanged (AppCompat)

I need the handwriting orientation changes in android because I want the activity to be recreated.

But I also need to determine when the orientation change was made.

Can these two combined tasks be completed simultaneously?

+4
source share
1 answer

Activity , :

@Override
public void onConfigurationChanged(Configuration config) {
    super.onConfigurationChanged(config);
    // Check for the rotation
    if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "LANDSCAPE", Toast.LENGTH_SHORT).show();
    } else if (config.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "PORTRAIT", Toast.LENGTH_SHORT).show();
    }
}

, , configChanges

<activity android:name=".MyActivity"
          android:configChanges="orientation|keyboardHidden"
          android:label="@string/app_name">

. Android 3.2 (API 13+), , . API (13+), : android:configChanges="orientation|screenSize"

-//-

EDIT

configChanges, .

Google

Android: configChanges

, . , , . , onConfigurationChanged() .

, , onConfigurationChanged(), Activity onCreate(). , onCreate() Activity

+2

Source: https://habr.com/ru/post/1651519/


All Articles