I programmed game, which is supposed to use .startActivity on activity which should display score, the problem is, that instead of properly displaying the activity, i’m getting “Deprecated Thread methods are not supported”. I googled this error and i removed all Thread.stop() in my application, but it did not helped. Could there be any other reason why i’m getting this type of error?
public class GameFrame extends Activity implements OnTouchListener, OnLossListener {
Panel game;
@Override
public void onCreate(Bundle savedInstanceState) {
Display d=getWindowManager().getDefaultDisplay();
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Point p=new Point(d.getWidth(),d.getHeight());
game=new Panel(this,p);
setContentView(game);
game.setOnTouchListener(this);
game.setOnLossListener(this);
}
public boolean onKeyDown (int kc,KeyEvent ke){
if (kc==23){
game.shoot();
}
return true;
}
public void onPause(){
super.onPause();
game.thread.setState(false);
game.mech.setState(false);
this.finish();
}
@Override
public boolean onTouch(View v, MotionEvent me) {
if (v.equals(game)){
game.setPosOfPlane((int)me.getX());
}
return true;
}
@Override
public void lost(int score) {
Intent i=new Intent (this,EndGame.class);
i.putExtra("score",score+"");
startActivity (i);
}
}
I can’t tell you what exactly is the problem, but I can give you some hints.
First of all you usually create a thread when starting your application and let it run until you want to exit your game (user pressed BACK). Other than that you only pause your game thread, e.g. when you’re displaying another activity or your app is temporarily suspended (user pressed HOME).
If you want to end your game thread, just let it die naturally. Usually such thread runs in some sort of a loop, so you just exit this loop and the thread will terminate on its own. You usually call
join()on the game thread from the main thread to block it until the game thread dies.You should never manipulate thread’s state directly.