Manuel
Manuel

Reputation: 63

Android 12: Layout is not properly displayed when using startActivityForResult

I'm migrating a android app from target SDK 30 to 31:

    compileSdkVersion 31
buildToolsVersion '31.0.0'
defaultConfig {
    applicationId "some.app.id"
    minSdkVersion 16
    targetSdkVersion 31
    versionCode xyz
    versionName "xyz"
    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    vectorDrawables.useSupportLibrary = true
    multiDexEnabled true
}

There is one activity that behaves differently depending on how it is opened:

After some tests, the problem seems to be related to the resizing of the UI. Its not happening anymore. Buttons are not resized based on its content, elements set to GONE still take the space etc.

Anyone else came across this issue?

Upvotes: 0

Views: 94

Answers (1)

Manuel
Manuel

Reputation: 63

I tried to reproduce the issue in a new project without success.

Eventually I found that this problem occured due to changes to the UI in the wrong thread: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

Running the code in "runOnUiThread" solved the issue.

Upvotes: 1

Related Questions