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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:46:59+00:00 2026-06-18T02:46:59+00:00

Is it possible to do splash screen that will execute HTTP request and if

  • 0

Is it possible to do splash screen that will execute HTTP request and if this request is executing too long, i.e. 7-10 seconds, then abort the request and jump to the main activity?

The below code is what I did, but it doesn’t work – the timeout isn’t working, the HTTP request and jumping are working. As I understand, it’s possible to use the AsyncTask‘s get() method or handler with delay. Get() method should be in separate thread but it doesn’t work. How to do this task?

EDIT:

public class SplashActivity extends Activity {
private static final String TAG = "SplashActivity";
private Handler handler = new Handler();
private Runnable r;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_layout);

    if (Helpers.isNetworkConnected(getApplicationContext())) {
        Log.d(TAG, "Has Internet");
        final DownloadFAQ downloadFAQ = new DownloadFAQ();
        new Thread(new Runnable() {
            public void run() {
                try {
                    Log.d(TAG, "Timing...");
                    downloadFAQ.execute().get(1000, TimeUnit.MILLISECONDS);

                    SplashActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            Log.d(TAG, "redirect");
                            redirect();
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (TimeoutException e) {
                    downloadFAQ.cancel(true);
                    Log.d(TAG, "Task has benn canceled");
                    if (downloadFAQ.isCancelled())
                        redirect();
                }
            }
        }).start();
    } else {

        r = new Runnable() {
            public void run() {
                redirect();
            }
        };
        handler.postDelayed(r, 2500);
    }
}

private class DownloadFAQ extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... params) {
        Log.d(TAG, "Execute task");
        ServerAPI server = new ServerAPI(getApplicationContext());
        server.serverRequest(ServerAPI.GET_FAQ, null);
        return null;
    }
}

private void redirect() {
    Intent i = new Intent(SplashActivity.this, TabsActivity.class);
    startActivity(i);
    finish();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    handler.removeCallbacks(r);
}

}

  • 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-18T02:47:00+00:00Added an answer on June 18, 2026 at 2:47 am

    because you are trying to start AsyncTask again inside doInBackground when it’s still running . change your code as to get it work :

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_layout);
        downloadFAQ = new DownloadFAQ();
        new Thread(new Runnable() {
                public void run() {
                    try {
                        downloadFAQ.execute().get(2000, TimeUnit.MILLISECONDS);
    
                      SplashActivity.thisrunOnUiThread(new Runnable() {
                            public void run() {
                             // start Activity here
                              Intent i = new Intent(SplashActivity.this,
                                                          TabsActivity.class);
                              SplashActivity.this.startActivity(i);
                              SplashActivity.this.finish();
                           }
                      });
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (TimeoutException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }).start();
    }
    

    and you will need to remove downloadFAQ.get(2000, TimeUnit.MILLISECONDS); from doInBackground method change your AsyncTask as

    private class DownloadFAQ extends AsyncTask<Void, Void, Void> {
        @Override
        protected Void doInBackground(Void... params) {
            ServerAPI server = new ServerAPI(getApplicationContext());
            server.serverRequest(ServerAPI.GET_FAQ, null);
            return null;
        }
    
        protected void onPostExecute(Void result) {
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to show a splash screen in WPF that has animation. I
Possible Duplicate: Displaying splash screen for longer than default seconds I am developing a
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Is it possible to have different image for different language for Splash screen in
Possible Duplicate: splash screen for Universal application for ipad and iphone How to keep
Possible Duplicate: Localization of Default.png is not working My splash screen has English text
In my splash screen I have a TextView that it shows the name of
My app takes a few seconds to load and I have a splash screen.
Is it possible to replace the splash screen for iOS and Android with a
This is my sistuation A1 = Splash Screen Activity A2 = Main Activity A3

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.