Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:02:43+00:00 2026-06-17T08:02:43+00:00

I have following 2 class class CallNetworkMethod extends AsyncTask<Void, Void, Void> { @Override protected

  • 0

I have following 2 class

class CallNetworkMethod extends AsyncTask<Void, Void, Void>
{

    @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));
    }

}

====================================================

public class TwitterUtils {

static ArrayList<String> 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;
    }
}

}

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:02:44+00:00Added an answer on June 17, 2026 at 8:02 am

    Currently you are calling TwitterUtils.isAuthenticated(prefs) in onPostExecute because onPostExecute always execute on UI thread then you are getting networkonmainthreadexception exception .

    to avoid this issue use a Boolean Flag to get return from doInBackground and show it in TextView in onPostExecute as:

    class CallNetworkMethod extends AsyncTask<Void, Void, Void>
    {
      public static boolean status=false;
        @Override
        protected Void doInBackground(Void... params) {
    
           status=TwitterUtils.isAuthenticated(prefs);
    
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
    
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            //updateLoginStatus();
            loginStatus.setText("Logged into Twitter : " + status);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have the following class: class risc { // singleton protected: static unsigned long
I have following class in Java code: public class CHRTreeCreator extends IndexCreator { ...
I have following class for a form: class Application_Form_ContactForm extends Zend_Form { public function
I have following class public abstract class Rule { protected Rule() { Nodes =
Suppose I have following class structure: class Base {} class A extends Base {}
Suppose I have following class @Entity public class Customer extends Model { @Id public
If have following class public abstract class MyBaseClass : BaseClass { public override string
I have following situation class base { public: virtual void Accepted(SOCKET s) //// Event
I have following class with a constructor : public class TestAdapter { protected static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.