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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:19:11+00:00 2026-06-11T16:19:11+00:00

I use AsyncTask to perform some data load over http requests in background. The

  • 0

I use AsyncTask to perform some data load over http requests in background. The http request use a session variable. This variable can become invalid and the http request will return an error.
In this case the user have to relogin.

So, can I just use something like this:

protected void onPostExecute(IData data) {
            //
            // !!On Error data object is null!!
            // 
    if (mCallback != null) {
        mCallback.onTaskComplete(data);
    }
}

And in the Activity which implements the Callback interface I just check if the data object is null and change the Activity to the “MainActivity” Login form.

    public void onTaskComplete(IData data) {
    if (data == null) {
        Intent intent = new Intent(ReadDataActivity.this, MainActivity.class);
        deleteCurrentSavedSession();
        startActivity(intent);
    } else {
           // Do something with the data
        }
    }

Is this a bad idea? Should I better use ExecutorService and execute it as a “normal” thread which checks if the session is still valid?

ExecutorService executor = Executors.newFixedThreadPool(2);
executor.execute(sessionCheckWorker);
executor.shutdown();
while (!executor.isTerminated()) {

}
// Wait until session check task is finished and decide which Activity to load

Best Regards

  • 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-11T16:19:12+00:00Added an answer on June 11, 2026 at 4:19 pm

    Go for ExecutorService. It is meant specifically for such timer related tasks. I would also suggest you to use handlers in combination with ExecutorService, since handlers give you more control over such tasks as compared to Asynctask.

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

Sidebar

Related Questions

All I want to do is use AsyncTask to do a http request. This
This is my Activity class where i use AsyncTask to get data from a
I load a list of some data. I do it in AsyncTask and I
I'm implementing a class which extends AsyncTask and I perform an http request within
I want to lock back button while my data process. I use AsyncTask to
I was trying to use AsyncTask for lazy load of images in the adapter.
I am trying to perform a http-get-request and show the download progress to the
I'm trying to use ASyncTask to handle networking in the background of my android
How can i use AsyncTask Class to showing dialog when execute a task??? class
I wanted to use AsyncTask to load images to the ListView. private class LoadImageTask

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.