From 4d9f1a878fbdb785f47e631b28ece85cd5ceb3c1 Mon Sep 17 00:00:00 2001 From: oliexdev Date: Wed, 2 Dec 2020 11:20:43 +0100 Subject: [PATCH] catch illegal state argument if context is lost --- .../BluetoothSettingsFragment.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java index c77ec282..efc12ee8 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java @@ -160,21 +160,25 @@ public class BluetoothSettingsFragment extends Fragment { new Handler().post(new Runnable() { @Override public void run() { - BluetoothDeviceView notSupported = new BluetoothDeviceView(requireContext()); - notSupported.setDeviceName(requireContext().getString(R.string.label_scale_not_supported)); - notSupported.setSummaryText(requireContext().getString(R.string.label_click_to_help_add_support)); - notSupported.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent notSupportedIntent = new Intent(Intent.ACTION_VIEW); - notSupportedIntent.setData( - Uri.parse("https://github.com/oliexdev/openScale/wiki/Supported-scales-in-openScale")); + try { + BluetoothDeviceView notSupported = new BluetoothDeviceView(requireContext()); + notSupported.setDeviceName(requireContext().getString(R.string.label_scale_not_supported)); + notSupported.setSummaryText(requireContext().getString(R.string.label_click_to_help_add_support)); + notSupported.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent notSupportedIntent = new Intent(Intent.ACTION_VIEW); + notSupportedIntent.setData( + Uri.parse("https://github.com/oliexdev/openScale/wiki/Supported-scales-in-openScale")); - startActivity(notSupportedIntent); - } - }); - deviceListView.addView(notSupported); - } + startActivity(notSupportedIntent); + } + }); + deviceListView.addView(notSupported); + } catch(IllegalStateException ex) { + Timber.e(ex.getMessage()); + } + } }); } }, 20 * 1000);