SBoss
SBoss

Reputation: 9215

App not responding

I'm writing a game for android, and whenever the player dies, he should get a small alert dialog to write his name for the high score list. The game loop continues too run however, and I'd prefer to keep it like that. But it seems as if the loop is blocking the dialog. Also, if you press restart, the game is restarted but user inputs are ignored. After a while the "This app is not responding..." message pops up.

Code called in main activity

public static boolean addHighScore(int score) {
if (mHiScores != null) {
    if (mHiScores.checkIfFits(score)) {
    if (Looper.myLooper() == null)
        Looper.prepare();
    mCurScore = score;
    mTextDialog.show();
    return true;
    }
}
return false;
}

PS: his = his / her, he = he / she etc.

EDIT: The alert dialog is never shown, if that wasn't really brought over clearly.

Upvotes: 0

Views: 807

Answers (2)

wonne
wonne

Reputation: 108

Don't use a Thread if you want to show data provided by the thread in your UI-Thread. Use AsyncTask instead.

Upvotes: 0

Aurelian Cotuna
Aurelian Cotuna

Reputation: 3081

You can try to start a new thread containing the addHighScore function. This will not stop your game and it can run in background. Also when the user finish to insert his name, your thread will end and the game can restart with data that was provided by the thread. Just an idea.

Upvotes: 1

Related Questions