Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Potentially existing text notifications will be canceled before showi…
Browse files Browse the repository at this point in the history
…ng a new one.

With some Android platforms `Toast` notifications do not interrupt each other. Using the same `Toast` object a notification which has become invalid is now canceled.

This commit relates to issue #1.
  • Loading branch information
dhebbeker committed Mar 17, 2018
1 parent 252bcb8 commit 165d450
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class MainActivity extends AppCompatActivity implements GameBoardInterfac
private final SymbolButton[] symbols = new SymbolButton[4];
private final Game game = new Game(this, symbols);
private View startGameButton;
private Toast notification = null;

@Override
protected void onCreate(final Bundle savedInstanceState)
Expand Down Expand Up @@ -102,7 +103,11 @@ public void run()
@Override
public void notifyUser(final String userMessage)
{
Toast notification = Toast.makeText(this, userMessage, Toast.LENGTH_LONG);
if (notification != null) // check if a notification has been created before
{
notification.cancel(); // cancel potential previous notification
}
notification = Toast.makeText(this, userMessage, Toast.LENGTH_LONG);
notification.show();
}

Expand Down

0 comments on commit 165d450

Please sign in to comment.