I am trying to freeze background running processes when mobile screen is off and when screen get on processes should restart automatically in lower android versions. But i am not able to find any code to achieve this functionality.So if anyone knows about this then please help.
Asked
Active
Viewed 50 times
-1
-
Don't show any notification in the notification bar. I will automatically be killed by the android. If you killed instantly create a broadcast as answered by @Juan Sancho and kill your service. – Rajneesh Shukla Jun 25 '19 at 10:17
-
Let me know if you still stuck – Rajneesh Shukla Jun 25 '19 at 10:18
2 Answers
1
Try this :)
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
//Stop your service
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// Start your service
}
}
}, intentFilter);

Juan Sancho
- 321
- 1
- 7
0
You can stop your background service in onStop()
method of activity life cycle by using stopService(intent);
and again start in onResume()
method of activity life cycle by using startService(intent);

Sanjay Bhalani
- 2,424
- 18
- 44
-
thanks for the suggestion but i want to freeze all background running processes including other apps running processes – p.k. Jun 25 '19 at 10:45
-
-
-
i mean can i stop other apps running processes in lower version of android – p.k. Jun 26 '19 at 08:03
-
-
try this one but it won't work for me ActivityManager.killBackgroundProcesses(PackageName) – Sanjay Bhalani Jun 26 '19 at 08:54
-
https://stackoverflow.com/questions/6303615/how-do-task-managers-kill-apps – Sanjay Bhalani Jun 26 '19 at 08:55
-
link u share is for kill background process but i want to freeze processes not want to kill but thanks for the answer – p.k. Jun 26 '19 at 10:31
-