My Android application does not store the high score -
I am developing a simple game in Android and even I follow the steps found in the net My app is never hysoser saved, I am using shared pages to store, but I know that the problem is there because I do not understand exactly how to use it. Hope people can help me, thanks.
package com.example.memory; Import android App Import android.content.Intent; Import android.content.SharedPreferences; Importroid.os.Bundle; Import android.view.View; Import android.view.View.OnClickListener; Import android.widget.Button; Import android.widget.TextView; Public Square uses the last activity OnClickListener {TextView levelReachedText; TextView Best Sound; Int Level Level Reachach, BestScore; Intent to intent; Protected void onCreate (bundled saved instenstate) {super.onCreate (SavedInstanceState); SetContentView (R.layout.finals); LevelReachedText = (TextView) this.findViewById (R.id.nivel); BestScore Text = (text view) this.findViewById (RID.best); Button Menu = (Button) Search ViewById (R.id.inicio); Menu.setOnClickListener (this); Intent = getIntent (); LevelReached = intent.getIntExtra ("net", 1); Shared preferences = this.getSharedPreferences ("Best Score", MODE_PRIVATE); Int savedScore = preferences.getInt ("selectedScore", 0); LevelReachedText.setText ("You Level Reached" + Layered); If (savedScore & quot; levelReached) {bestScore = savedScore; } And {best = score = level; } BestScoreText.setText ("reached maximum level" + layered); } Click Public Zero (see V) {Switch (v.getId ()) {Case R.id.inicio: Shared Priorities = this.getSharedPreferences ("mejorScore", MODE_PRIVATE); Preferences.edit () PutInt ("selectedScore", BestScore) .commit (); This.finish (); break; }}}}
You save the score value in mejorScore And trying to get it from the best score . Either change
shared preferences = this.getSharedPreferences ("mejorScore", MODE_PRIVATE); to
shared preferences = this.getSharedPreferences ("bestScore", MODE_PRIVATE); Or vice versa.
Comments
Post a Comment