How to Handle networkonmainthreadexception in Andoid?
<p>I have following 2 class</p>

<pre><code>class CallNetworkMethod extends AsyncTask&lt;Void, Void, Void&gt;
{

    @Override
    protected Void doInBackground(Void... params) {

        if (TwitterUtils.isAuthenticated(prefs)) {
            sendTweet();
        } else {

            Intent i = new Intent(getApplicationContext(), TwPrepareRequestTokenActivity.class);
            i.putExtra("tweet_msg",getTweetMsg());
            startActivity(i);
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        // TODO Auto-generated method stub
        super.onPostExecute(result);
        //updateLoginStatus();
        loginStatus.setText("Logged into Twitter : " + TwitterUtils.isAuthenticated(prefs));
    }

}
</code></pre>

<p>====================================================</p>

<pre><code>public class TwitterUtils {

static ArrayList&lt;String&gt; friens=null;

public static boolean isAuthenticated(SharedPreferences prefs) {

    String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
    String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

    AccessToken a = new AccessToken(token,secret);
    Twitter twitter = new TwitterFactory().getInstance();

    twitter.setOAuthConsumer(TwConstants.CONSUMER_KEY, TwConstants.CONSUMER_SECRET);

    twitter.setOAuthAccessToken(a);


    try {



        **twitter.getAccountSettings();**

        return true;
    } catch (TwitterException e) {
        return false;
    }
}

}
</code></pre>

<p>I got the exception when running this code(networkonmainthreadexception).I debug this code and found the location where exception come out. It is <strong>twitter.getAccountSettings();</strong>  .I think this method should run inside a AsynTask but i dont know how to do that.</p>
