android - Trouble with Code Executing After startActivity() -
i creating quiz app. in code below, want code after startactivity(intent);
execute once activity has finished. app in current state display question text , answer buttons. once user makes choice, next question , corresponding answer buttons displayed split second before new activity launched. want app go straight new activity upon answer selection, , once new activity has finished, display next question.
my code:
intent intent = new intent(getapplicationcontext(), newactivity.class); startactivity(intent); // helper variable keep track of current question questioncounter++; if(questioncounter < numgamequestions) { // displays next question playgame(randquestionsarr[questioncounter]); }
1 add definition
public static final int request_code = 100;
2 replace startactivity() startactivityforresult();
startactivityforresult(intent, request_code );
3 before finishing activity in child activity,call setresult method;
setresult(result_ok);
4 add things in onactivityresult method in parent activity.
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == request_code ) { if (resultcode == result_ok) { system.out.println("ok"); } } }
Comments
Post a Comment