Prevent some code from being executed in program flow
<p>In my onCreate method in main activity i have some code which is checking if wifi connection is enabled. If it isn't i'm trying to automatically enabled it (very important now ) <strong>and after that</strong> i want to make other stuff ( starting service ..and other things). Its very important that it must be enabled <strong>before proceeding</strong> with execution !</p>

<p>I already tried AsyncTask , but with no luck. (code is still executing down below, before task in AsyncTask is completed ).</p>

<p>How to achive that some code will execute <strong>AFTER</strong> certain task is completed? </p>

<p>EDIT:</p>

<p>my onCreate in main activity</p>

<pre><code>wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); 

    if(!wifiManager.isWifiEnabled()) {


        new Asyn(this, progress, wifiManager);


        } 


    startService(new Intent(intentt));
</code></pre>

<p>Asyn Class</p>

<pre><code>public class Asyn extends AsyncTask&lt;Context, Integer, Long&gt; {

private Context context;
private ProgressDialog pd;
private WifiManager wm;

   public Asyn(Context context, ProgressDialog pd, WifiManager wm) {
     this.context = context;
     this.pd = pd;
     this.wm = wm;
    }



@Override
protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
    pd = ProgressDialog.show(context, "", "Enabling wifi");

}

@Override
protected Long doInBackground(Context... params) {

    wm.setWifiEnabled(true);


    return null;
}

@Override
protected void onPostExecute(Long result) {
    // TODO Auto-generated method stub
    super.onPostExecute(result);

    pd.dismiss();

}
</code></pre>

<p>}</p>

<p>I dont want to execute "startService" until wifi is not fully enabled!</p>
