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 9040469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:59:19+00:00 2026-06-16T09:59:19+00:00

I’m new to android, please halp. This is a really simple scenario, there’s an

  • 0

I’m new to android, please halp.

This is a really simple scenario, there’s an actionbar, and when a tab is selected, I need to send an http request to get an article list, when the response arrives, update a listview and here’s where I got this exception.

I’m aware that I should isolate network operations from UI thread, so I implement the network functions in an AsyncTask class.

The most weird part is, before I try to get the article list, I have actually called a network function once to log in, and that just works fine, no exceptions! And guess what, if I replace the get article list call with log in call, it works fine, too. All the code are just the same, except the arguments differ.

Here’s how I do it, since too many modules will use the network module, I use a static wrapper:

UI -> Static Factory -> New AsyncTask -> Response arrives -> Call Static callback function in Static Factory -> Call callback function in UI

AsyncTask doInBackground

@Override
protected HttpResponse doInBackground(String... params) {
    // TODO Auto-generated method stub
    String uri = params[0];
    HttpGet get = new HttpGet(uri);
    try {
        return _client.execute(get);
    }
    catch(Exception e) {
        e.printStackTrace();
        return null;
    }   
}

AsyncTask post execute

    @Override
    protected void onPostExecute(HttpResponse result) {
        //Do something with result
        if (result != null) {
            try {
                JSONObject json = FormJsonFromResponse();
                Command.OnTaskComplete(json);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

static wrapper code:

@Override
    public static void OnTaskComplete(JSONObject json) {
        // TODO Auto-generated method stub
        if(_callback != null) {
            _callback.OnCommandComplete(json);
        }
    }

Here’s how I call asynctask in static wrapper:

public static void LogIn(String user, String pass) {
    new NetworkTask().execute(_uriPrefix + login, _user, _pass);
}
  • 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-16T09:59:20+00:00Added an answer on June 16, 2026 at 9:59 am

    Revise your AsyncTask following this pattern:

    @Override
    protected JSONObject doInBackground(String... params) {
        // TODO Auto-generated method stub
        String uri = params[0];
        HttpGet get = new HttpGet(uri);
        try {
            HttpResponse response = _client.execute(get);
            return FormJsonFromResponse();
        }
        catch(Exception e) {
            e.printStackTrace();
            return null;
        }   
    }
    

    AsyncTask post execute

    @Override
    protected void onPostExecute(JSONObject result) {
        //Do something with result
        if (result != null) {
            try {
                Command.OnTaskComplete( result );
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.