From 20a9fd715f0b0e5f230b3f9cfc50f587a9e49a5b Mon Sep 17 00:00:00 2001 From: jvde-github Date: Mon, 22 Jul 2024 22:03:34 +0200 Subject: [PATCH] fix sharedpreferences null crash --- app/build.gradle | 4 ++-- .../jvdegithub/aiscatcher/ui/main/WebViewMapFragment.java | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0594dd0..5f23609 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.jvdegithub.aiscatcher" minSdk 23 targetSdk 34 - versionCode 103 - versionName '1.03' + versionCode 104 + versionName '1.04' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { diff --git a/app/src/main/java/com/jvdegithub/aiscatcher/ui/main/WebViewMapFragment.java b/app/src/main/java/com/jvdegithub/aiscatcher/ui/main/WebViewMapFragment.java index e066932..da6dfc7 100644 --- a/app/src/main/java/com/jvdegithub/aiscatcher/ui/main/WebViewMapFragment.java +++ b/app/src/main/java/com/jvdegithub/aiscatcher/ui/main/WebViewMapFragment.java @@ -120,9 +120,11 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) { webView.setVisibility(View.INVISIBLE); // Restore localStorage content as early as possible - String localStorageContent = getSharedPreferences().getString("localStorageContent", null); - if (localStorageContent != null) { - webView.evaluateJavascript("localStorage.setItem('settings', " + localStorageContent + ");", null); + if(getSharedPreferences()!= null) { + String localStorageContent = getSharedPreferences().getString("localStorageContent", null); + if (localStorageContent != null) { + webView.evaluateJavascript("localStorage.setItem('settings', " + localStorageContent + ");", null); + } } }