I would like to launch an activity multiple times with a button and when it has been called 5 times execute another. I have tried the following but can't get it to work.
public class SumasActivity extends AppCompatActivity {
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sumas);
final String stage_temp = getIntent().getStringExtra("stage");
final int stage = Integer.parseInt(""+stage_temp)+1;
Toast.makeText(SumasActivity.this, "Stage: "+stage, Toast.LENGTH_SHORT).show(); //Muestra 2 (envio 1 desde una actividad que lanza a esta) pero se cierra cuando más abajo intento volver a iniciar esta misma actividad enviando de nuevo la variable stage incrementada.
...
bt1.setOnClickListener(new AdapterView.OnClickListener() {
@Override
public void onClick( View view) {
if(stage==5) {
Intent i = new Intent(SumasActivity.this, Inicio.class);
i.putExtra("dificultad", dificultad);
i.putExtra("stage", stage);
startActivity(i);
}else{
Intent i = new Intent(SumasActivity.this, SumasActivity.class);
i.putExtra("dificultad", dificultad);
i.putExtra("stage", stage);
startActivity(i);
}
}
}
}
}
I answer myself, the problem was because I was mixing string and int.
I have changed this:
For this:
and it works for me.