I have following code:
mQuestions=DictionaryDbWrapper.getInstance().getQuestionsSequence(
this.getIntent().getStringExtra(ApplicationUtilities.TEST_CATEGORY_PARAMETER), 50);
mQuestionsCount=mQuestions.size();
Log.e("count", String.valueOf(mQuestionsCount));
if (mQuestionsCount==0) {
Log.e("1", "111");
Toast.makeText(this, "В данной категории нет слов", Toast.LENGTH_LONG).show();
this.finish();
}
makeQuestion();
mQuestions is empty ArrayList, and I see that count equals 0 on Log always. Also I see 1/111 record on my Log always too. But my activity doesn’t do a finish method!
makeQuestion is method that needn’t work with empty mQuestion (it throw Exception). But If I make a comment for makeQuestion then finish method works well! Method for this code works on main thread (it is executed from onCreate() method).
Please, suggest where I am going wrong.
Thanks in advance.
The finish() function is non-blocking, this means that the execution will continue while the activity is finishing in background.
To solve your problem, add a return statement after the finish() call.