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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:20:00+00:00 2026-06-09T16:20:00+00:00

I have very little experience with android development, i have made a simple app

  • 0

I have very little experience with android development, i have made a simple app with a webview, i want to be able to alert the user when there is no network connectivity. however i am not able to get the alert dialog to show up. The code compiles fine without any errors or warnings.

MainActivity.java

package dk.zerone.vuc;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    public final boolean networkCheck() {
        ConnectivityManager connec =  (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    // ARE WE CONNECTED TO THE NET
    if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
    connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ||
    connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) {
        return true;
    } else if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  ) {
        return false;
    }
    return false;
}

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

    if(networkCheck()) {

        // INTERNET IS AVAILABLE, DO STUFF..

        } else {
            AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
            alertDialog.setTitle("Reset...");
            alertDialog.setMessage("R u sure?");

            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            } });
            alertDialog.show();
        }

    /* Splash screen */
    // ...

    /* WebView */
    WebView webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient()); 

    setContentView(webview);

    Uri uri = Uri.parse("http://mobil.vucfyn.dk/mobil");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

I am testing the code in the emulator, disabling the network with F8 or Airplane mode does not trigger the dialog or network check.

What am i doing wrong?

Kind 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-09T16:20:02+00:00Added an answer on June 9, 2026 at 4:20 pm

    For one thing you are not showing your activity to the user in each case.You are launching Browser in oncreate.
    You are not using WebView to load the url, you are using the preloaded Browser to show your URL. Use

    webview.loadUrl("http://mobil.vucfyn.dk/mobil");
    

    instead of last 3 lines in your oncreate function

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

Sidebar

Related Questions

I have very little experience designing databases, and now I want to create a
Is there a way to install node.js in IIS7? I have very little experience
What I want to do should be very simple, however I have little to
I have very little experience in web development, so this may be a very
I have very little experience with ASP.NET and I am doing some self-training before
I have very little experience working with sockets and multithreaded programming so to learn
I have very little experience using Sharepoint but a good amount using Visual Studio
Warning: I have very little JavsScript experience. In my past programming experience, I usually
I have a strong database background but very little practical experience with ms sql
I have 0 experience with python, very little with regex and I'm trying to

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.