How To Receive An Int Through An Intent
I am passing an int through an Intent but I do not know how to receive it because I have to receive an intent from the OnCreate method but if I place it there I can't compare it to
Solution 1:
You need to get the data passed inside onCreate method not in the declaration.
Also you are not sending a Bundle, you are sending a String in the Intent. So you need to get the String from the Intent.
Do it like this
publicclassGuessOneextendsActionBarActivity {
int randone;
int contone;
Bundle bundle;
StringmaxPressed="";
intmaxcont=0;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_guess_one);
maxPressed = getIntent().getStringExtra("maxNumberPressed");
try {
maxCont = Integer.parseInt(maxPressed);
}
catch (NumberFormatException e) {
e.printStackTrace();
}
}
//the rest of the codeAlso send data like this
Intent wall = newIntent(HomeActivityPro.this, GuessOne.class);
wall.putExtra("maxNumberPressed", conttext.getText().toString());
startActivity(wall);
Post a Comment for "How To Receive An Int Through An Intent"