Skip to content

bug(demo-android): getParcelableExtra crashes on API < 33 in PostsListActivity #443

@jkmassel

Description

@jkmassel

Context

In PR #433 (feat/demo-edit-existing-posts), the new PostsListActivity uses the two-argument getParcelableExtra(String, Class) API without a version guard.

Bug

In PostsListActivity.onCreate(), two calls use the API 33+ form:

val postType = intent.getParcelableExtra(EXTRA_POST_TYPE, PostTypeDetails::class.java)
val configuration = intent.getParcelableExtra(MainActivity.EXTRA_CONFIGURATION, EditorConfiguration::class.java)

The two-argument Intent.getParcelableExtra(String, Class<T>) overload was added in API 33 (TIRAMISU). The project's minSdk is 24. On any device running API 24–32, this will crash with NoSuchMethodError.

EditorActivity already has the correct version-branched pattern:

val configuration =
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
        intent.getParcelableExtra(MainActivity.EXTRA_CONFIGURATION, EditorConfiguration::class.java)
    } else {
        @Suppress("DEPRECATION")
        intent.getParcelableExtra<EditorConfiguration>(MainActivity.EXTRA_CONFIGURATION)
    }

No desugaring or AndroidX IntentCompat is present in the project to mitigate this.

Impact

The app will crash immediately when navigating to the posts list on any device running Android 12L (API 32) or below — covering every API level from 24 through 32.

Fix

Apply the same Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU branching pattern used in EditorActivity to both getParcelableExtra calls in PostsListActivity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions