i have set some condition in the cocos2d-android game app, if the condition=0, the current gamelayers score will be displayed in Gameover.class as highscore, but here when the condition becomes zero, i'm not able to get next layer(Gameover.class) which displays highscore and an option to save the player name.
if (Counter<=0)
{
Intent mainScore = new Intent(CCDirector
.sharedDirector().getActivity(), GameOver.class);
mainScore.putExtra("totalscore", countScore);
CCDirector.sharedDirector().getActivity()
.startActivity(mainScore);
System.out.println("intent");
CCDirector.sharedDirector().getActivity().finish();
}
i have used the above code, the print statement is not getting, i guess this line CCDirector.sharedDirector().getActivity()
.startActivity(mainScore);
has problem, please can anybody solve this issue?
This is the Gameover.class
public class GameOver extends BaseActivity {
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();
}