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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:40:40+00:00 2026-06-05T02:40:40+00:00

My Android game needs to get some information about players from my server. I

  • 0

My Android game needs to get some information about players from my server. I do this with a simple HTTP GET request, which I placed inside a thread.

The code I am using is below. When my server is up and running the app works fine. When my server is not responding (either because it’s busy or down), however, the app crashes.

Instead of the app crashing I would like to display a “Network is busy” message to the user and send him back to the main activity, but not sure how to do it.

I tried to create a dialog inside the Catch section, thinking this would show if my server was down, but it’s not showing and the app crashes.

Any ideas how I can solve this?

public void run(){      
        String urlstring = "http://www.mydomain.com/?param=test"; 
        try{                        
                URL url = new URL(urlstring);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                line = reader.readLine();   
        }
        catch(Exception e){
            Dialog d2 = new Dialog(context);
            d2.setContentView(R.layout.dialog2);
            d2.show();
        } 
}

Update: I think I found the issue looking at logcat. Even with the server down my BufferedReader was returning an empty string, and I was trying to use that down the road.

  • 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-05T02:40:41+00:00Added an answer on June 5, 2026 at 2:40 am

    So at first, you should check your response. This is best approach

    if (urlConntection.getResponseCode() == HttpURLConnection.HTTP_OK) {
      // method body
    }
    else {
       /// get some info for example with Toast or Dialog
    }
    

    You should decide to use runOnUiThread when you want to update UI from Non-UI thead

    YourActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
    
                }
            });
    

    Or use Handler or AsyncTask

    When you decide to use AsyncTask, you can simply show almost everything

    protected void onProgressUpdate(String... data) {
      if(data[0].equals("error")) {
        Toast.makeText(Activity.this, "Connection is busy!", Toast.LENGTH_SHORT).show(); 
    }
    

    also simply show Dialog. It’s up to you.

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

Sidebar

Related Questions

I am making an android game that should delete some falling images from the
I am developing an android game, in which i have some trains moving on
I'm programming an Android multi-player game, which basically consist of a server where the
I am developing an Android Game. In this game some trains are moving on
I'm developing an Android game in Java which uses Lua scripts. To execute these
I'm developing an Android game that uses the orientation sensor to get the rotation
I am going to create game for android, this game has multiplayer mode, so
I am an experienced programmer with C++/C# trying to get into the android game
I want to develop a small game in Android. But for this I need
I'm trying to make my first android game and to do this I made

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.