为什么我的应用程序在第二次启动时无法正确打开?我认为它没有被正确销毁

时间:2014-05-05 00:15:01

标签: android andengine

大家好,我想知道你是否可以帮助我,在我的游戏中,我已经覆盖了onresume,onpause,ondestroy和onstop。如果我点击主菜单来评价应用程序,它会将我链接到应用程序商店,然后我可以选择从应用程序商店打开或按后退按钮。如果我从应用程序商店按下打开而不是继续打开,它会再次打开应用程序,并在启动画面后显示一个空白屏幕。有什么想法吗?

@Override
public void onResume() {
super.onResume();

try {
    if (ResourcesManager.getInstance().musicTrack != null
            && ResourcesManager.getInstance().allowMusic
            && wasMusicBeingPlayed) {
        ResourcesManager.getInstance().musicTrack.play();
        wasMusicBeingPlayed = true;
    }
    SharedPreferences sharedpreferences = getSharedPreferences(
            SHARED_PREFS_MAIN, 0);
    musicPlaying = sharedpreferences.getBoolean("music", true);
    soundPlaying = sharedpreferences.getBoolean("sound", true);
    ResourcesManager.getInstance().settings(musicPlaying, soundPlaying);

    if (adView != null) {
        adView.resume();
    }

            } catch (Exception e) {

}

}

@Override
public void onPause() {
super.onPause();
try {

    if (ResourcesManager.getInstance().musicTrack != null
            && ResourcesManager.getInstance().allowMusic
            && ResourcesManager.getInstance().musicTrack.isPlaying()
            && GameScene.getGameScene().isMusicTrackPlaying) {
        ResourcesManager.getInstance().musicTrack.pause();
        wasMusicBeingPlayed = true;

    } else {
        wasMusicBeingPlayed = false;
    }
    if (adView != null) {
        adView.pause();
    }
} catch (Exception e) {

}

}

/** Called before the activity is destroyed. */
@Override
public void onDestroy() {
super.onDestroy();
try {
    int highSCORE = ResourcesManager.getInstance().getHighScore();

    SharedPreferences settings = getSharedPreferences(
            SHARED_PREFS_MAIN, 0);
    SharedPreferences.Editor editor = settings.edit();
    if (highSCORE > highScore) {
        editor.putInt("highest", highSCORE);
    }

    editor.putBoolean("music", ResourcesManager.getInstance()
            .isMusicAllowed());
    editor.putBoolean("sound", ResourcesManager.getInstance()
            .isSoundAllowed());
    // Commit the edits!
    editor.commit();

    // Destroy the AdView.
    if (adView != null) {
        adView.destroy();
    }
} catch (Exception e) {

}
if (gameHasLoaded) {
    System.exit(0);
}

}

public void rateApp() {
    Uri uri = Uri.parse("market://details?id=" + this.getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {
        this.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
                .parse("http://play.google.com/store/apps/details?id="
                        + this.getPackageName())));
    }
}

0 个答案:

没有答案