This is something incomprehensible, but if you still want to do it,
in onCreate of each action that Internt uses, writes this code,
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true);
and in onPause activity record,
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(false);
this needs to be done for WIFI for GPRS / EDGE / 3G, you may have to enable disable flight mode in the same way.
UPDATE TO DO FROM EVERYONE
Take one SharedPreference and put one boolean isAppRunning = true every time you go in onCreate() any of your actions and every time put False in every kind of onDestroy() activity.
Now create one broadcast receiver that listens for the NETWORK_STATE_CHANGED action and in this receiver onReceive() checks the value of SharedPreference,
If the boolean variable SP is True, then let WIFI get enabaled, and if false - your application does not work, then turn off WIFI again.
source share