Skip to content

Commit 7e45ea1

Browse files
authored
Implement ext functions to parse data from Bundle
1 parent e5f4c99 commit 7e45ea1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ai.elimu.common.utils
2+
3+
import android.os.Build
4+
import android.os.Bundle
5+
6+
fun <T> Bundle?.getParcelableCompat(key: String, clazz: Class<T>): T? {
7+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
8+
this?.getParcelable(key, clazz)
9+
} else {
10+
@Suppress("DEPRECATION")
11+
this?.getParcelable(key)
12+
}
13+
}
14+
15+
fun <T : android.os.Parcelable> Bundle?.getParcelableArrayListCompat(key: String, clazz: Class<T>)
16+
: java.util.ArrayList<T>? {
17+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
18+
this?.getParcelableArrayList(key, clazz)
19+
} else {
20+
@Suppress("DEPRECATION")
21+
this?.getParcelableArrayList(key)
22+
}
23+
}

0 commit comments

Comments
 (0)