Android application life cycle and using static

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.

+5
java android
Feb 05 '15 at 10:44
source share

No one has answered this question yet.

See similar questions:

86
Android Static Object Lifecycle
55
Android Application Class Life Cycle

or similar:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up Android emulator development?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to keep Android activity state by saving instance state?
2097
Is there a way to run Python on Android?
1844
What is "Context" on Android?
1636
Java inner class and static nested class
882
A static way to get "Context" in Android?
646
Calling metadata "Unable to add window null token - this is not an application" with getApplication () as context



All Articles