Onactivityresult Not Working Properly
So, I have this quiz game and I have bunch of popup screens (for wrong answer, for game end, for time's up and so on). My game has 15 level, each level different number of question
Solution 1:
first change this: startActivityForResult(i, 1);
to this: startActivityForResult(i, MY_REQUEST );
When you put 1 , its mean it will always be 1 when you return from the next activity. You should use different request code for each case
Your code should be like this: protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);
if(requestCode == MY_REQUEST){
if(resultCode == RESULT_OK){
nextQuestion();
}
}else{
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK) {
nextQuestion();
timer.start();
break;
}
case 1:
if(resultCode == RESULT_OK) {
nextQuestion();
timer1.start();
break;
}
case 2:
if(resultCode == RESULT_OK) {
nextQuestion();
timer2.start();
break;
}
case 3:
if(resultCode == RESULT_OK) {
nextQuestion();
timer3.start();
break;
}
}
}
}
if you dont break, the case will move to the next one until it end or find breaks.
Solution 2:
You have the RequestCode hardcoded to 1 in your StartActivity !! This is why OnActivityResult() always matches 1.
startActivityForResult(i, 1);
Solution 3:
You forgot to put break statments thats why control comes to the last case statement everytime, you can fix this by adding it
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK) {
nextQuestion();
timer.start();
}
break;
case 1:
if(resultCode == RESULT_OK) {
nextQuestion();
timer1.start();
}
break;
case 2:
if(resultCode == RESULT_OK) {
nextQuestion();
timer2.start();
}
break;
case 3:
if(resultCode == RESULT_OK) {
nextQuestion();
timer3.start();
}
}
Post a Comment for "Onactivityresult Not Working Properly"