意图无法获得高分

时间:2013-07-20 09:43:26

标签: android android-intent android-activity cocos2d-iphone cocos2d-android

终于结束了cocos2d游戏开发,为了得到这个,我将totalScore发送到下一个gameover.class活动,如果它很高并想显示得分和玩家名,则设置为高分。我已经做到了这一点,但是一旦游戏结束,我就无法进行gameover.class活动,不知道我哪里出错了。请帮帮我

这是我的游戏玩法层(第一个活动)

 if (spriteCounter<=0)
                {


                    Intent mainScore = new Intent(CCDirector.sharedDirector().getActivity(), GameOver.class);
                    mainScore.putExtra("totalscore", countScore);
                    CCDirector.sharedDirector().getActivity().startActivity(mainScore);
                    System.out.println("------------");
                    CCDirector.sharedDirector().getActivity().finish();

                 }

gameover.class(第二活动)

public class GameOver extends MainActivity {

ImageView playagain, home;
String[] columns;
int Score = 0;
String TOTALSCORE = "score";
String PLAYERNAME = "playername";

SQLiteDatabase db;

SharedPreferences sharedPreference = CCDirector.sharedDirector()
        .getActivity().getSharedPreferences("sharedPreference", 0);

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.gameover);

    int totalscore = getIntent().getIntExtra("totalscore", -1);
    SharedPreferences sharedPreference = CCDirector.sharedDirector()
            .getActivity().getSharedPreferences("sharedPreference", 0);
    long temp_totalscore = (long) totalscore;
    try {
        String bp_totalscore = sharedPreference.getString(TOTALSCORE, null);
        String bp_playername = sharedPreference.getString(PLAYERNAME, null);
        if (totalscore > Integer.parseInt(bp_totalscore)) {

            showSettingsDialog(temp_totalscore);

        }

    } catch (Exception e) {
        showSettingsDialog(temp_totalscore);
    }

    intiatizeviews();
    viewlisteners();

}

private void showSettingsDialog(long totalscore) {
    EnterHighscore dialog = new EnterHighscore(this, totalscore);

    dialog.show();

}

private void intiatizeviews() {
    playagain = (ImageView) findViewById(R.id.playagainimageView);
    home = (ImageView) findViewById(R.id.homeimageView);

}

1 个答案:

答案 0 :(得分:0)

  

但是一旦游戏结束,我就无法获得gameover.class活动

假设您的问题是,在启动此新活动时,应用程序崩溃,logcat显示找不到gameover类,您是否在清单文件中注册了此GameOver Activity