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?