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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:26:55+00:00 2026-05-28T17:26:55+00:00

I’m in the process of setting up a background task that makes network calls;

  • 0

I’m in the process of setting up a background task that makes network calls; however, my development has stalled as a result of the fact that I am unable to get my AsyncTask that I have set up to work, what I did was I placed toasts at various points in the code to see where the problem was occurring. I realized that I would get a toasts at all points right up to the pre execute method of the AsyncTask; however, in the doInBackground and postexecute, I would get nothing.

Why is this? and if this can’t be done what is the work around?

package com.testapp2.second.activities;

import java.util.Date;

import com.testapp2.second.OTweetApplication;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.IBinder;
import android.widget.Toast;

public class StatsCheckerService extends Service {
    private OTweetApplication app;
    private Twitter twitter;
    User user;

    @Override
    public IBinder onBind(Intent arg0) {
       return null;
    }

    @Override
    public void onCreate() {
       super.onCreate();
       app = (OTweetApplication) getApplication();
       twitter = app.getTwitter();

       Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (app.isAuthorized()) {

            Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG)
                .show();
            new toastTwitterInBg();
        }
        return START_STICKY;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
    }

    private class toastTwitterInBg extends AsyncTask<Void, Void, User> {

        @Override
        protected User doInBackground(Void... arg0) {
            try {
                user = twitter.verifyCredentials();
                Toast.makeText(StatsCheckerService.this, "async tasks do in background", Toast.LENGTH_LONG).show();
            } catch (TwitterException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return user;
        }

        @Override
        protected void onPostExecute(User result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Toast.makeText(StatsCheckerService.this, "async tasks on post execute finished", Toast.LENGTH_LONG).show();
        }

    }
} 
  • 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-05-28T17:26:57+00:00Added an answer on May 28, 2026 at 5:26 pm

    As someone else already pointed out, toasts will not work in doInBackground as that runs on a separate thread. Also, are you actually executing your AsyncTask?

    Shouldn’t this be:

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
      // ....
      new toastTwitterInBg().execute();
      // ....
    }
    

    Note the .execute().

    • 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 &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to

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.