I tried to do this
@Override
protected void onDestroy() {
super.onDestroy();
SharedPreferences.Editor editor=this.getMyView().getSp().edit();
editor.putInt("score",this.getMyView().getScores()+this.getMyView().getScore());
editor.commit();
and it doesn't work
can someone pls help me?
its MyView class the class is working the problem isn't there and it is not the entire class case it is too long
package com.example.brickv5;
import...
public class MyView extends View {
private ArrayList<Brick> brickList = new ArrayList<Brick>();
private LocalTime time;
private Brick brick;
private Killer killer;
private Bitmap back;
private int score=0;
private Timer timer;
private SharedPreferences sp= getContext().getSharedPreferences("scores",0);
public SharedPreferences getSp() {
return sp;
}
private int scores;
private int width=Resources.getSystem().getDisplayMetrics().widthPixels;
private int height=Resources.getSystem().getDisplayMetrics().heightPixels;
public MyView(Context context) {
super(context);
for (int i = 0; width-(width-20)/5*(i+1)>=0; i++) {
int x = width-(width-20)/5*(i+1);
int y = (300);
brick = new Brick(x, y, this);
brickList.add(brick);
}
back = BitmapFactory.decodeResource ( this.getResources (), R.drawable.background2);
back=Bitmap.createScaledBitmap(back,width,height,false);
killer = new Killer(width/2, height-height/3, 0, 0, this);
killer.setX(killer.getX()-killer.getBitmap().getWidth()/2);
scores=sp.getInt("score",0);
timer=new Timer(width,100);
}