0

I have this activity which is called MainPutShipActivity and I want to start it again so it will do the same thing but it doesn't even enter the OnCreate method.

here is the MainPutShipActivity:

public class MainPutShipActivity extends Activity implements OnClickListener{

private static final int MAX = 10;
private String name1,name2;
private Player plr = new Player();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_put_ship);

    Intent intent = getIntent();

    plr = (Player) intent.getSerializableExtra("player");
    name1 = plr.getName1();
    name2 = plr.getName2();

}

public void finished() {
    Intent in;
        }
    if (plr.isTreated() == false) {
        plr.setArr1(arr);
        plr.setShip1(ships);
        this.finish();
        in = new Intent(this,MainPutShipActivity.class);
        in.putExtra("player", this.plr);
    }
    else {
        plr.setArr2(arr);
        plr.setShip2(ships);
        in = new Intent(this, MainGameActivity.class);
        in.putExtra("player", this.plr);
    }
    plr.setTreated(true);
    this.finish();
    startActivity(in);
}

When i enter the finished() procedure for the first time it suppose to start the MainPutShipActivity again but when it starts the activity, it skips the onCreate and goes straight to the finished() method for some reason.

I would be very glad for any kind of help.

  • Possible duplicate of [How to send an object from one Android Activity to another using Intents?](http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents) – Tophandour Feb 17 '16 at 14:12
  • post your second activity code. – Ritt Feb 17 '16 at 14:28
  • Maybe you can use parcelable, please check this link http://androcode.es/2012/12/trabajando-con-parcelables/ – Jorge Moreno Feb 17 '16 at 14:31

1 Answers1

2

Pay attention to the key passed in the intent

Instead of :

plr = (Player) i.getSerializableExtra("plr");

set

plr = (Player) i.getSerializableExtra("player");

because you are setting

in.putExtra("player", this.plr);
Chol
  • 2,097
  • 2
  • 16
  • 26