I have a main activity that is loaded and performs a network check, this works fine.
I would ideally like to move the code for this into another class (most likely in another package to keep things neat), however i do not know how to then call the methods in this class from the original main one.
If i do try and call directly i end up with m methods needing to be made static (which wont work) so assuming that i need to create an instance of the class but can't get the syntax right.
Any help with this would be appreciated as i feel answering this would help me understand the concept.
Current code for main activity is :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
NetworkCheck.isInternetOn();
{
Toast.makeText(this, UpdateCheck(), Toast.LENGTH_LONG).show();
}
Current code for NetworkCheck class is :
public class NetworkCheck
{
public final boolean isInternetOn()
{
ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
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;
}
}
I would ideally like to move the code for this into another class (most likely in another package to keep things neat), however i do not know how to then call the methods in this class from the original main one.
If i do try and call directly i end up with m methods needing to be made static (which wont work) so assuming that i need to create an instance of the class but can't get the syntax right.
Any help with this would be appreciated as i feel answering this would help me understand the concept.
Current code for main activity is :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
NetworkCheck.isInternetOn();
{
Toast.makeText(this, UpdateCheck(), Toast.LENGTH_LONG).show();
}
Current code for NetworkCheck class is :
public class NetworkCheck
{
public final boolean isInternetOn()
{
ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
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;
}
}