"System services not available to Activities before onCreate()" Error message?
Error is due to create this object creation.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
you should do this after onCreate has been invoked.
I think it's because your instantiating an onClick listener before on create is called. Try instantiating the onClick listener inside the onCreate()
method.
This may or may not be the case with the AlertDialog
too, but I'm not entirely sure.
Technically I believe it is the following line that causes the problem:
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
However, because this is being called within the isNetworkConnected()
method which in turn is called within your onClick method, moving the instantiation of the onClick fixes the problem.
The clue is in the exception System services not available to Activities before onCreate()