It’s so slow change mode of Data network from enable to disable or disable to enable. Is there anyway to do it fast?
I use this code for change mode of Data network.
Method dataMtd;
try {
dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
dataMtd.setAccessible(true);
dataMtd.invoke(mgr, true);
} catch (Exception e) {
e.printStackTrace();
}
If you want to use this , you must add these permissions :
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.CHANGE_NETWORK_STATE" />
You can use
System.gc();to kill all of process and it can help to improve your performance for change network state.