I have a problem with passing int variable to another class. I've tried many methods of passing this variable but none have worked. Help me pass variable randomNum from MainActivity to HistoryActivity. Thanks!
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
........
int min, max;
max = 1;
min = 0;
int randomNum = min + (int) (Math.random() * ((max - min) + 1));
int backgroundImages[] = {R.drawable.background1,
R.drawable.background2};
final Drawable backgroundImage = getResources().getDrawable(
backgroundImages[randomNum]);
linearLayoutBackground.setBackgroundDrawable(backgroundImage);
// // WHAT TO DO NOW POGA
buttonWhatToDoNow.setOnClickListener(new View.OnClickListener() {
.........
}
});
buttonHistory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this, HistoryActivity.class);
startActivity(i);
finish();
}
});
}
}
public class HistoryActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
.......
randomNum =..............;
int backgroundImages[] = {R.drawable.background1,
R.drawable.background2};
final Drawable backgroundImage = getResources().getDrawable(
backgroundImages[randomNum]);
linearLayoutBackground.setBackgroundDrawable(backgroundImage);
}
}