]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Always check isFinishing before displaying a Toast.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Wed, 13 Jun 2018 20:42:01 +0000 (22:42 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Wed, 13 Jun 2018 20:42:01 +0000 (22:42 +0200)
Just in case it fixes the rare random crashes.

src/com/hughes/android/dictionary/DictionaryActivity.java

index 0b09e6da8855fdf4e151e5499b1cb2a0545b5ddd..3062b7249a14e2c4f4ab31b6d98bcd76a37ef628 100644 (file)
@@ -238,8 +238,9 @@ public class DictionaryActivity extends AppCompatActivity {
             }
             dictRaf = null;
         }
             }
             dictRaf = null;
         }
-        Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()),
-                       Toast.LENGTH_LONG).show();
+        if (!isFinishing())
+            Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()),
+                           Toast.LENGTH_LONG).show();
         startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
         finish();
     }
         startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
         finish();
     }
@@ -413,7 +414,8 @@ public class DictionaryActivity extends AppCompatActivity {
         }
 
         if (dictFilename == null) {
         }
 
         if (dictFilename == null) {
-            Toast.makeText(this, getString(R.string.no_dict_file), Toast.LENGTH_LONG).show();
+            if (!isFinishing())
+                Toast.makeText(this, getString(R.string.no_dict_file), Toast.LENGTH_LONG).show();
             startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
             finish();
             return;
             startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
             finish();
             return;
@@ -522,8 +524,9 @@ public class DictionaryActivity extends AppCompatActivity {
                     typeface = Typeface.createFromAsset(getAssets(), fontName);
                 } catch (Exception e) {
                     Log.w(LOG, "Exception trying to use typeface, using default.", e);
                     typeface = Typeface.createFromAsset(getAssets(), fontName);
                 } catch (Exception e) {
                     Log.w(LOG, "Exception trying to use typeface, using default.", e);
-                    Toast.makeText(this, getString(R.string.fontFailure, e.getLocalizedMessage()),
-                            Toast.LENGTH_LONG).show();
+                    if (!isFinishing())
+                        Toast.makeText(this, getString(R.string.fontFailure, e.getLocalizedMessage()),
+                                Toast.LENGTH_LONG).show();
                 }
                 break;
         }
                 }
                 break;
         }
@@ -1244,9 +1247,10 @@ public class DictionaryActivity extends AppCompatActivity {
             out.close();
         } catch (Exception e) {
             Log.e(LOG, "Unable to append to " + wordList.getAbsolutePath(), e);
             out.close();
         } catch (Exception e) {
             Log.e(LOG, "Unable to append to " + wordList.getAbsolutePath(), e);
-            Toast.makeText(this,
-                           getString(R.string.failedAddingToWordList, wordList.getAbsolutePath()),
-                           Toast.LENGTH_LONG).show();
+            if (!isFinishing())
+                Toast.makeText(this,
+                               getString(R.string.failedAddingToWordList, wordList.getAbsolutePath()),
+                               Toast.LENGTH_LONG).show();
         }
     }
 
         }
     }