finish executing asynctask first before comparing the boolean
<p>I have 2 classes: checkenrol.java and allcourses.java</p>

<p>checkenrol extends AsyncTask. I also have a global boolean named "alreadyEnrolled" in checkenrol. </p>

<p>allcourses will execute checkenrol with 2 parameters.</p>

<p>The idea is that:</p>

<ul>
<li>allcourses will load a list of courses.</li>
<li>the user will click on a course, at the background it will run the checkenrol class. if the user is already enrolled, global boolean "alreadyEnrolled" will be set to true else false.</li>
<li>allcourses now will output if the user is already enrolled or not DEPENDING ON THE VALUE OF THE BOOLEAN</li>
</ul>

<p>My problem is that the execution of the Asynctask and the comparing of the boolean is done simultaneously. </p>

<p>To further illustrate here are fragments of my code:</p>

<p>This is my checkenrol.java</p>

<pre><code>public class checkenrol extends AsyncTask &lt;String, Void, String&gt; {
    public static boolean alreadyEnrolled = false;
    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        ...

        if (res.equals("1")) {
            alreadyEnrolled = true;
        }
        else {
            alreadyEnrolled = false;
        }
        ...
    } ...
</code></pre>

<p>This is my allcourses.java</p>

<pre><code> checkenrol ce = new checkenrol();
        ce.execute(param1, param2); 

        if (checkenrol.alreadyEnrolled == true) {
            //redirect to subject's home
            System.out.println("Already Enrolled");
        }
        else if (checkenrol.alreadyEnrolled == false){
            System.out.println("Not yet enrolled");
        }
</code></pre>

<p>When I click on the item that I am ALREADY enrolled to, it outputs "Not yet enrolled" but the second time I click it, it will output "Already enrolled".</p>

<p>Sorry for the long post. hope you will help me :)</p>
