OnPause and OnStop() called immediately after starting activity

Let us understand why the lifecycle methods are called multiple times. Here is an important code comment documented in ActivityThread, which is responsible for executing the activities of the application process. We accomplish this by going through the normal startup (because activities expect to go through onResume() the first time they run, before their window … Read more

Does the Android OS release a wakelock if the app or service holding it is killed?

WakeLock Implementation Overview When we use pm.newWakeLock to create a new wakelock, the PowerManager simply creates a new WakeLock object and returns. The WakeLock object is not a binder object, so it cannot be used through multiple processes. However, in that WakeLock object, it contains a Binder object named mToken. WakeLock(int flags, String tag) { … Read more

Keep a Service running even when phone is asleep?

Note: This post has been updated to include the JobScheduler API of the Android Lollipop release. The following is still a viable way, but can be considered deprecated if you’re targeting Android Lollipop and beyond. See the second half for the JobScheduler alternative. One way to do recurrent tasks is this: Create a class AlarmReceiver … Read more

BroadcastReceiver Vs WakefulBroadcastReceiver

There is only one difference between BroadcastReceiver and WakefulBroadcastReceiver. When you receive the broadcast inside onReceive() method, Suppose, BroadcastReceiver : It is not guaranteed that CPU will stay awake if you initiate some long running process. CPU may go immediately back to sleep. WakefulBroadcastReceiver : It is guaranteed that CPU will stay awake until you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)