Skip to content

Commit

Permalink
bug/osmdroid#680: crash in PreferenceActivity
Browse files Browse the repository at this point in the history
There's a call to `Toast.makeText` outside of the UI thread, which is not possible in Android and systematically leads to a crash.

Impacted class:
* `PreferenceActivity`: embedded the call to `Toast.makeText` inside an `Activity.runOnUIThread` method.
  • Loading branch information
monsieurtanuki committed Aug 26, 2017
1 parent cd618a6 commit 1b2af6e
Showing 1 changed file with 8 additions and 5 deletions.
Expand Up @@ -327,11 +327,14 @@ public void run() {
SqlTileWriter sqlTileWriter = new SqlTileWriter();
boolean b = sqlTileWriter.purgeCache();
sqlTileWriter.onDetach();
sqlTileWriter = null;
if (b)
Toast.makeText(PreferenceActivity.this, "SQL Cache purged", Toast.LENGTH_SHORT).show();
else
Toast.makeText(PreferenceActivity.this, "SQL Cache purge failed, see logcat for details", Toast.LENGTH_LONG).show();
final String title = b ? "SQL Cache purged" : "SQL Cache purge failed, see logcat for details";
final int length = b ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG;
PreferenceActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(PreferenceActivity.this, title, length).show();
}
});
}
}).start();

Expand Down

0 comments on commit 1b2af6e

Please sign in to comment.