i declare int score = 100 in my 1st activity and use it to my 2nd activity, now the int score is declared as array in 2nd act. but its declared in local variable so how can i use it to my 3rd activity?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level2);
ans1 = findViewById(R.id.ans1);
btn1 = findViewById(R.id.btn1);
Intent i = getIntent();
final int[] score2 = {i.getIntExtra("fscore", 0)};
scr1 = (TextView) findViewById(R.id.scr1);
scr1.setText(String.valueOf(score2[0]));
btn1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
String answer = ans1.getText().toString();
if (score2[0] == 0)
{
Toast.makeText(getApplication(),"You Lose!", Toast.LENGTH_SHORT).show();
gameover();
}
else
{
if (answer.equalsIgnoreCase("ANSWER2"))
{
Toast.makeText(getApplication(),"CORRECT!!", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplication(),"Wrong Answer -10 Points", Toast.LENGTH_SHORT).show();
score2[0] = score2[0] - 10;
scr1.setText(String.valueOf(score2[0]));
}
}
}
});
}
public void gameover()
{
Intent intent = new Intent(this, gameover.class);
startActivity(intent);
}
}