私はmainActivityにユーザーが選択できる約5つのオプションがあるアプリを持っています。そのうちの1つをクリックすると新しいアクティビティが開きますが、本質的に5つすべてが同じ見出しで異なるアクティビティを開きます。新しく開かれたアクティビティでは、複数の評価バーを使用して、指定された属性にポイントを委任します。 SharedPreferenceを使用すると、アクティビティ全体を保存することができます。バックアウトするときに、同じオプションをクリックしても、すべてが消えませんか?または、SharedPreferenceを使用して個別の評価バーの値を保存する必要がありますか?SharedPreferenceを使用してAndroidでアクティビティを保存しますか?
ボタンクリックから開くアクティビティのコードです。何かがひどく間違っているので、今クラッシュしています。助言がありますか?関数内
public class MageSkillScreen extends AppCompatActivity
{
public float skillPoints = 10;
public float strengthRating;
public float intellectRating;
public float wisdomRating;
public float dexterityRating;
public float totalSkill;
public float mageStrength;
public float mageDexterity;
public float mageIntellect;
public float mageWisdom;
public RatingBar strengthBar;
public RatingBar intellectBar;
public RatingBar wisdomBar;
public RatingBar dexterityBar;
Button submit;
//preferences
SharedPreferences magePref;
boolean rememberRatings = true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mage_skill_screen);
strengthBar = (RatingBar) findViewById(R.id.mageStregth);
intellectBar = (RatingBar) findViewById(R.id.mageInt);
wisdomBar = (RatingBar) findViewById(R.id.mageWisdom);
dexterityBar = (RatingBar) findViewById(R.id.mageDext);
submit = (Button) findViewById(R.id.submit);
}
@Override
public void onPause()
{
SharedPreferences.Editor edit = magePref.edit();
edit.putFloat("strengthPts", strengthBar.getRating());
edit.putFloat("dexterityPts", dexterityBar.getRating());
edit.putFloat("intellectPts", intellectBar.getRating());
edit.putFloat("wisdomPts", wisdomBar.getRating());
//edit.putString("pointsLeft", ptsRemaing.getText().toString());
edit.commit();
super.onPause();
}
@Override
public void onResume()
{
super.onResume();
rememberRatings = magePref.getBoolean("mageRatings", true);
mageStrength = magePref.getFloat("strengthPts", 0.0f);
mageDexterity = magePref.getFloat("dexterityPts", 0.0f);
mageIntellect = magePref.getFloat("intellectPts", 0.0f);
mageWisdom = magePref.getFloat("wisdmPts", 0.0f);
}
}
アクティビティ全体を保存するように属性/プロパティを保存する必要があります。 –
コードを投稿してください。 – Ritesh