From aea5ddfe674127f88a8fa7ebbe23f5004d5e9b1d Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Tue, 11 May 2021 11:15:11 +0700 Subject: [PATCH] Add try catch to prevent the crashing from bad parcelable exception (#92) --- .../core/LocalizationActivityDelegate.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/localization/src/main/java/com/akexorcist/localizationactivity/core/LocalizationActivityDelegate.kt b/localization/src/main/java/com/akexorcist/localizationactivity/core/LocalizationActivityDelegate.kt index e5a10f9..ffdfae1 100644 --- a/localization/src/main/java/com/akexorcist/localizationactivity/core/LocalizationActivityDelegate.kt +++ b/localization/src/main/java/com/akexorcist/localizationactivity/core/LocalizationActivityDelegate.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.Intent import android.content.res.Configuration import android.content.res.Resources +import android.os.BadParcelableException import android.os.Handler import android.os.Looper import java.util.* @@ -106,10 +107,14 @@ open class LocalizationActivityDelegate(val activity: Activity) { // Check that bundle come from locale change. // If yes, bundle will be remove and set boolean flag to "true". private fun checkBeforeLocaleChanging() { - val isLocalizationChanged = activity.intent?.getBooleanExtra(KEY_ACTIVITY_LOCALE_CHANGED, false) ?: false - if (isLocalizationChanged) { - this.isLocalizationChanged = true - activity.intent?.removeExtra(KEY_ACTIVITY_LOCALE_CHANGED) + try { + val isLocalizationChanged = activity.intent?.getBooleanExtra(KEY_ACTIVITY_LOCALE_CHANGED, false) ?: false + if (isLocalizationChanged) { + this.isLocalizationChanged = true + activity.intent?.removeExtra(KEY_ACTIVITY_LOCALE_CHANGED) + } + } catch (e: BadParcelableException) { + e.printStackTrace() } }