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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:57:04+00:00 2026-05-20T13:57:04+00:00

I have developed an android 2.1 application which consumes Soap Web Service. When my

  • 0

I have developed an android 2.1 application which consumes Soap Web Service.
When my application gets started, it first checks whether there is internet connectivity or not.

If so, it will display corresponding activity.
If not then it will display an Activity(NetworkErrorActivity) giving information about network errors and all.

The problem is if there is no internet connectivity, it shows me the NetworkErrorActivity.
Now when user presses back button it redirects the user to Home.
I have overriden onBackPressed method like this :

@Override
public void onBackPressed() {

        Intent setIntent = new Intent(Intent.ACTION_MAIN);
        setIntent.addCategory(Intent.CATEGORY_HOME);
        setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(setIntent); 
        return;
    }

After pressing back button, it shows me the android home screen.
But the problem is when i start the same application again, it shows me the NetworkErrorActivity even if there is network connectivity. Could not start the application from Main Launcher Activity. It always shows me the same Activity again and again.

  • 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-20T13:57:05+00:00Added an answer on May 20, 2026 at 1:57 pm

    I use an AlertDialog (not an Activity) to inform the user about needing a network connection with an option to take them to network settings (to enable mobile/wi-fi) connections. If they choose to click ‘Cancel’ instead I force the main activity to finish().

    Check for network connection in main activity onResume() and if there’s no connection then call CreateNetErrorDialog()…it isn’t possible to use BACK to dismiss the dialog – only Cancel which kills the main activity.

    Example…

    protected void CreateNetErrorDialog(String errorMessage) {
        Log.d(TAG, "CreateNetErrorDialog() entered...");
    
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(errorMessage)
        .setTitle("Unable to connect")
        .setCancelable(false)
        .setPositiveButton("Settings",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent i = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
                    startActivity(i);
                }
            }
        )
        .setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    MyMainActivity.this.finish();
                }
            }
        );
        AlertDialog alert = builder.create();
        alert.show();
        Log.d(TAG, "Exiting CreateNetErrorDialog()...");
    }
    

    EDIT: Call the CreateNetErrorDialog from the onPostExecute() method of your AsyncTask – it runs on the UI thread (doInBackground doesn’t). Example from my own code…

    private class FileDownloader extends AsyncTask<String, Void, Void> {
        private Boolean Success = false;
        private String ResultString = "";
    
        @Override
        protected Void doInBackground(String... params) {
            try {
                // Do whatever
            }
            catch (Exception e) { // <-- Use the correct exception type
                  ResultString = "Some error message";
            }
        }
    
        @Override
        protected void onPostExecute(Void result) {
            if (!Success)
                CreateNetErrorDialog (ResultString);
            else
                // Do whatever
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed some reusable android component which is basically a class . This
I'm having a go at developing my first android application and have never really
I have developed a VB.NET WCF service that recives and sends back data. When
I have developed about 300 Applications which I would like to provide with multi-language
I am developing an application for the Android platform which contains 1000+ image filters
I have developed some classes with similar behavior, they all implement the same interface.
I have developed some custom DAO-like classes to meet some very specialized requirements for
We have developed our website(Business users website) in .net Framework 2.0 Our client us
We have developed a website that uses MVC, C#, and jQuery. In one of
We have developed a webservice that sits and runs in the context of a

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.