After my App Login, I need to check Internet Connection before every onClick
event and after every Fragment
is added or replaced.If Internet Connection is not Available the setContentView
should set another Fragment and as soon as the Internet get Available it should set the working fragment.
This is code for checking NetworkStatus
public class NetworkStatus {
public static String checkConnection(Context context){
ConnectivityManager connectivitymanager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if(connectivitymanager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState()==NetworkInfo.State.CONNECTED || connectivitymanager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()==NetworkInfo.State.CONNECTED){
return "true";
}else{
return "false";
}
}
This is code before performing any onClick
event
String NetworkStatus=NetworkStatus.checkConnection(getContext());
if(NetworkStatus.equals("false"))
{
alert.noInternetAlert(getActivity());
}
else
{
performAction();
}
Now How to setContentView
to different Fragment if no connection is available while replacing and adding new Fragments and resume to Fragment if connection get Available ?