5

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.

2 Answers 2

4

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.

1

I am pretty sure that calling finish() does not have the similar blocking effect of calling return.

Based on your code, you are assuming that finish() will have the same blocking effect of return.

Try this:

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();
}
else {
    makeQuestion();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.