Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep activity on when screen is off

I got a service that start a new activity, while screen is off. I want the activity to stay on paused mode, and not get to the stopped mode. Is there a way to achieve this?

like image 377
Chen Kinnrot Avatar asked Aug 27 '12 15:08

Chen Kinnrot


People also ask

Can Android activity run in background?

It seems like you want to run an activity in background when it quits. However, activity can't be run unless it's on foreground. In order to achieve what you want, in onPause(), you should start a service to continue the work in activity. onPause() will be called when you click the back button.


2 Answers

No. You don't have control over the Activity lifecycle. Any processes that you need to run while the screen is off must be executed in a Service. You must rebuild the application state whenever the screen is turned back on. Always assume the Activity can be wiped from memory at any time.

like image 97
DeeV Avatar answered Oct 01 '22 12:10

DeeV


You can't do that. it will be killed anyway. but you can use a Service to receive Broadcast of Intent.ACTION_SCREEN_ON and relaunch activity from Service. to restart your Activity from service check here

like image 29
Mahdi-Malv Avatar answered Oct 01 '22 13:10

Mahdi-Malv