This will be the correct code for Android:
calling init from MyApplication.onCreate()
public class Connectivity { static ConnectivityManager cm; public static void init(Context context){ cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); } public static boolean isConnected(){ activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnected(); return isConnected; }
Uses a static way for Android?
Will these static values ββstay longer than any activity or running service (which will end in an hour)?
The issue was related to the life cycle of the Android application class, but the discussion moved to the life cycle of the activity.
java android
Paul Verest Feb 05 '15 at 10:44 2015-02-05 10:44
source share