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

  • Home
  • SEARCH
  • 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 7840641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:51:20+00:00 2026-06-02T15:51:20+00:00

I have an onCreate method that runs the code below. In a nutshell the

  • 0

I have an onCreate method that runs the code below. In a nutshell the code retrieves data from the server and shows it on the screen for a messaging program. It only does it once, but I would like it to run the AsyncTask every 3 seconds (to try to simulate a chat). I’m pretty sure this is not the way to go about having a chat system but, I just need something that works for now (as a proof of concept) and I’ll focus on the correct way of implementing it later.

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.chat_box);// sd

        final Functions function = new Functions();
        final SharedPreferences prefs = PreferenceManager
                .getDefaultSharedPreferences(getBaseContext());
        whatroom = prefs.getString("chat", "null");

        new AsyncTask<String, Void, String>() {
            @Override
            protected String doInBackground(String... args) {
                return function.getInbox(args[0]);
            }

            @Override
            protected void onPostExecute(String result) {
                TextView inbox = (TextView) findViewById(R.id.inbox);
                ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1);
                progressBar.setVisibility(View.GONE);
                inbox.setText(result);
            }

        }.execute(whatroom);
    }

I’ve tried putting a simple while statement around the asynctask but, it just force closes.

  • 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-02T15:51:24+00:00Added an answer on June 2, 2026 at 3:51 pm

    You cannot reuse an AsyncTask instance. You would need to create fresh instances each pass of your loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
I have a method that runs when the app is opened. It is called
I have an Activity that contains 12 ImageViews. In onCreate method I load 12
I have a view that I'm loading, and my onCreate() method looks like this:
In my OnCreate method I have created a thread that listens to incoming message!
I have a FragmentActivity with the following onCreate method that seems to crash on
I have an Android app that in the onCreate() method, preloads a lot of
I have Activity with ListView inside it and in the onCreate method of the
In my activity oncreate method, i have called a service using OnStartCommand(). My requirement
I have a class derived from CTreeCtrl . In OnCreate() I replace the default

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.