Android FULL_WAKE_LOCK is deprecated but PARTIAL_WAKE_LOCK is not deprecated
Asked Answered
R

2

8

Here i mentioned the code for waking up the screen. i want the code is listen still the app is closed and the cpu is cleared and user can click the power button when ever my screen is unlock the app is sync like whatsapp.

    PowerManager pm =  (PowerManager)getSystemService(Context.POWER_SERVICE); 
    wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "whatever");
    super.onCreate(savedInstanceState);
    wl.acquire();
Rheotropism answered 28/5, 2015 at 10:40 Comment(0)
E
7

FULL_WAKE_LOCK is already deprecated and it's better to use the PARTIAL_WAKE_LOCK. This is the standard way to do this,

PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
Wakelock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
        "MyWakelockTag");
wakeLock.acquire();

For more way of implementation kindly visit the official link,

https://developer.android.com/training/scheduling/wakelock.html

Eureka answered 28/5, 2015 at 12:10 Comment(4)
Actually i want my app is working on under background also like whatsapp,hike any other method is available...Rheotropism
You can do that easily. Just implement a service and don't destroy while the user closes the app. Meanwhile use the WAKE_LOCK which will keep the service alive even after running in backgroundEureka
it is work when the process killed also it is workingRheotropism
It's not working on Android 8. Also adding wakeLock.release(); to onDestroy() not helps.Alumnus
D
0

Well you can consider an alternate, using JobScheduler for running background tasks while the app is still sleep for longer time thus preserving the battery. JobScheduler provides many methods to define job-execution conditions, therefore we can leverage that but it can be used for apps which are using Android 5.0 (API level 21) & above.

Dioptometer answered 20/11, 2018 at 13:49 Comment(3)
We are coding code, not literature. Can you please post code?Alumnus
Try this to safely implement a bg task without losing device's battery life and performance android.jlelse.eu/…Dioptometer
thank you for comment. It's so hard without any examples. I spent 2 days to explain JobScheduler and it not take effect on Oreo+ api..Alumnus

© 2022 - 2024 — McMap. All rights reserved.