How To Avoid User Turn Off The Screen Which Result In The Wifi Turned Off During Downloading
In my application, I use AsyncTask to download large files (300M+). I noticed that when the user turns off their screen (locks their device), the wifi will disconnect and the downl
Solution 1:
You required to implement WakeLock in your application. Wakelock will wake up the CPU incase of screen is off and performs the operations in normal ways.
Write down following code before starting the AsyncTask,
PowerManagerpm= (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLockwl= pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb");
wl.acquire();
You need to write wl.release();
on PostExecution() method. And you need to define permission in AndroidManifest.xml as follows,
<uses-permissionandroid:name="android.permission.WAKE_LOCK" />
Post a Comment for "How To Avoid User Turn Off The Screen Which Result In The Wifi Turned Off During Downloading"