Why does this activity not end?

I have the 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();

mQuestionsan empty ArrayList, and I see that count0 is always in the log. Also, I always see an entry 1/111in my journal. But my activity does not finish the method !

makeQuestionis a method that should not work with empty mQuestion(it throws an exception). But if I make a comment for makeQuestion, then the method finishworks well! The method for this code works in the main thread (it is executed from the method onCreate()).

Please tell me where I'm wrong.

Thanks in advance.

+5
source share
2 answers

finish() , , , .

, return finish().

+4

, finish() return.

, finish() return.

:

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();
}
+1

All Articles