I have got a class, which extends from BroadcastReceiver and gets called from AlarmManager. In the onReceive method I execute an AsyncTask, which fetches some data from the internet and stores the data in the local database of the application.
Do I need to acquire wakelock with:
@Override
public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
mWakeLock.acquire();
// execute AsyncTask
}
private void asyncTaskDone() {
mWakeLock.release();
}
in order to stop the CPU from sleeping or is it safe to execute the AsyncTask without a wake lock?