From 8f3a9c265c419dc3e8d3a74db32b25db925bd98d Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 21 Nov 2023 21:27:43 +0300 Subject: [PATCH] Fix a rare crash when opening a notification --- .../java/org/joinmastodon/android/MainActivity.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index 56cb30b9e..a11ac04c1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -6,6 +6,7 @@ import android.app.Fragment; import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; +import android.os.BadParcelableException; import android.os.Build; import android.os.Bundle; import android.util.Log; @@ -36,6 +37,8 @@ import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; public class MainActivity extends FragmentStackActivity{ + private static final String TAG="MainActivity"; + @Override protected void onCreate(@Nullable Bundle savedInstanceState){ UiUtils.setUserPreferredTheme(this); @@ -193,8 +196,14 @@ public class MainActivity extends FragmentStackActivity{ fragment.setArguments(args); showFragmentClearingBackStack(fragment); if(intent.getBooleanExtra("fromNotification", false) && intent.hasExtra("notification")){ - Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification")); - showFragmentForNotification(notification, session.getID()); + // Parcelables might not be compatible across app versions so this protects against possible crashes + // when a notification was received, then the app was updated, and then the user opened the notification + try{ + Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification")); + showFragmentForNotification(notification, session.getID()); + }catch(BadParcelableException x){ + Log.w(TAG, x); + } }else if(intent.getBooleanExtra("compose", false)){ showCompose(); }else if(Intent.ACTION_VIEW.equals(intent.getAction())){