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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:01:58+00:00 2026-06-11T19:01:58+00:00

In my app when I click on a menu button it will go to

  • 0

In my app when I click on a menu button it will go to an activity where I will load data and images from a remote server to a custom list view. The problem is if the WiFi is switched off, I’m getting a crash in the second activity. I have put the code in the try catch block and set the adapter to null in the catch section.So when i click the button it will go the activity and if the WiFi is off, since i set adapter = null in the catch activity will be shown with out a list view. How can i stay in the menu screen with out getting a crash. Any idea?

        Intent mainIntent = new Intent( SplashScreenActivity.this, GiftListActivity.class );
        SplashScreenActivity.this.startActivity( mainIntent );

This is my call to the second activity.

try{
    adapter = new GiftJewelryListAdapter(GiftListActivity.this, giftlist);
    itemsListView.setAdapter(adapter);
}
catch(Exception e){
    adapter=null;
    MyAlertDialog.ShowAlertDialog(GiftJewelryListActivity.this, "", "Check Network Connection", "OK");
}

I want to stay in the activity from which i called, after showing the message “check network connection”.What change should i do here?

  • 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-11T19:02:00+00:00Added an answer on June 11, 2026 at 7:02 pm

    You can check network availability in the activity from which you called the new activity. If a network is available, you can start the new activity.

    The below function is used to detect whether device is connected to a network or not.

     public static boolean isNetworkAvailable(Context context) {
         ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         if (connectivity != null) {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
               for (int i = 0; i < info.length; i++) {
                  if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                     return true;
                  }
               }
            }
         }
         return false;
      }
    

    You can invoke the function as shown below…

    if(!isNetworkAvailable(context))
         MyAlertDialog.ShowAlertDialog(GiftJewelryListActivity.this, "", "Check Network Connection", "OK")
    else{
         Intent mainIntent = new Intent( SplashScreenActivity.this, GiftListActivity.class );
         SplashScreenActivity.this.startActivity( mainIntent );
    }
    

    Dont forget to add permission in Manifest.XMl .

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    

    Hope it helps..

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

Sidebar

Related Questions

In this app I want that as I click on button the data from
I want to make a right click menu for my winforms app. It will
I'm attempting to call startActivity(myIntent) from the click of a menu button but my
I have a menu in my app android. When I click on add favorites,
When I click Settings in my application's menu, app crash instantly. I don't have
I'm in the midst of writing a slide show app (click a button, and
If I right-click my app from a network drive and select Run As |
When I click a button in my app a series of Javascript code is
Windows Phone 7.5 app. Designer has created Home.xaml in Blend that has 3 images(menu
In my app I bring up a context menu on long click in 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.