Skip to content

Commit 6a0ea90

Browse files
committed
[Parcelable EXT] Fixed API 33 issue
1 parent dc94e54 commit 6a0ea90

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
@file:Suppress("DEPRECATION")
2-
31
package de.davis.passwordmanager.ktx
42

5-
import android.os.Build
63
import android.os.Bundle
4+
import androidx.core.os.BundleCompat
75

86
fun <A> Bundle.getParcelableCompat(key: String, clazz: Class<A>): A? {
9-
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
10-
classLoader = clazz.classLoader
11-
getParcelable(key, clazz)
12-
} else
13-
getParcelable(key) as? A
7+
classLoader = clazz.classLoader
8+
9+
// Due to issues with the new getParcelable API in Android API 33, BundleCompat.getParcelable
10+
// is utilized here to ensure stable behavior across different Android versions. This workaround
11+
// selectively applies the new getParcelable implementation for API levels 34 and above,
12+
// addressing the reported bug.
13+
// For more details, refer to the Google Issue Tracker: https://issuetracker.google.com/issues/274185314
14+
// and the related discussion on Stack Overflow: https://stackoverflow.com/questions/76067109/getparcelable-crashes-due-to-null-iftable-in-agp-8
15+
return BundleCompat.getParcelable(this, key, clazz)
1416
}

0 commit comments

Comments
 (0)