akexorcist / Localization

[Android] In-app language changing library
Apache License 2.0
983 stars 154 forks source link

onConfigurationChanged orientation value does not change #82

Closed abdelhameedo closed 3 years ago

abdelhameedo commented 3 years ago

I added android:configChanges="fontScale|keyboardHidden|orientation|screenSize" to my Activity definition in the manifest to handle the rotation my self .

But when I extended LocalizationActivity the value of newConfig.orientation Doesn't change when I flip the device .

Following is the POC I have made to demonstrate this issue

class MyApplication : LocalizationApplication() {
    override fun getDefaultLanguage() = Locale.ENGLISH
}

//when I change it to class MainActivity : AppCompatActivity the newConfig.orientation change correctly 
class MainActivity : LocalizationActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
        Log.d("nav", "isLandScape=" + newConfig.orientation) // stay same  value on device rotation
    }
}

is there a workaround I can do to temporarily fix this ?

akexorcist commented 3 years ago

Handle the rotation by android:configChanges isn't recommended for most use cases.

Alternatively, you can detect the screen orientation changes from context.getResources().getConfiguration().orientation. And you can also use my ScreenOrientationHelper library for this situation.

akexorcist commented 3 years ago

I will close this issue because there's no response for a month.

But feel free to re-open it if anyone has issue-related problem.