I want my app to keep running when the screen is blank and locked.
This is an instrumentation app that runs when the phone is in the pocket, so we can blank the screen to save power.
Currently:
If the phone locks automatically the screen goes blank and the app terminates. When the phone is unlocked the app needs to be re-started.
If the phone is manually locked (with a tap on the power button) the screen goes blank, the app stays running, but the data to voice output stops "working". When the phone is unlocked the app is still running and the data to voice starts "working" again.
I don't think WakeLock will do that for me. It's a function that's more like a sticky bit, as in load and don't terminate unless there is a specif command to terminate.
Any pointers to what I should be doing would be appreciated - thanks - Rob
Why don't you start a 'Service' that your Activity's can bind to. This can run even when your App isn't.
http://developer.android.com/reference/android/app/Service.html
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
Imagine how a mp3 playing application works, same scenario.
Related
When Android device boot up, my application will start working in the foreground. User can put my application to background and he\she can use other applications for a desired long time.
When user stop interaction with phone for 30 seconds or lock the phone, my application will (if required)unlock the phone and continue to become active in the foreground.
How can achieve this?
User can put my application to background and he\she can use other
applications for a desired long time.
Starting from Android O you won't be able to reliably make your app work in background. System applies several restrictions on background processing especially running background services. Only alternative would be to create Foreground Service. But if OS detects that you are performing CPU intensive work this won't work either.
When user stop interaction with phone for 30 seconds or lock the
phone, my application will (if required)unlock the phone and continue
to become active in the foreground.
Unfortunately its not possible. Even if manage to get Administrator rights there is no API which allows developers to unlock the phone without user's action. This would be a privacy breach.
I am running an accelerometer based android app that will run for a few months while phone is on and does nothing else. Some phone allow display not to go to sleep at all which allows my app run fine infinitely. The screen also has only a black display and nothing else apart from background accelerometer listener and occasional http posts. My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
In short, it depends on your app architecture (otherwise i.e. music players would require to keep screen on to work). Depending on task you are really doing you may use Alarm Manager to periodically fire your code, or use Service.
I am building an android app with a map inside of it. It seems that when the user leaves the app (home button or back button), the app still uses cpu. The User and Kernal field jump from 0.00% to about 0.86% (at max) all the time after the user leaves the app. It seems to be killing the battery in my phone if I don't force close the app. Could the GPS be the issue of always searching? How could I stop all running processes with GPS if that is the issue?
thanks!
To kill a process you can use
android.os.Process.killProcess(android.os.Process.<PID>());
I would like my application to react to screen locking / putting phone into sleep. Based on some condition my application could decide to allow locking/sleep or to do something.
I want to use it that way:
User install my application (he don't have to run it all the time).
When phone want to go sleep or the screen is about to lock, my application receive the "message".
My application run some logic and decided either to allow lock/sleep or to perform some operation (that will prevent screen from lock this time).
If the user turn off the phone, my application can but don't have to react to it.
Is it possible to receive and react to screen locking and/or start of the sleep in order to prevent it (sometimes)?
Well, you can first let your app receive the ACTION_SCREEN_OFF intent, which would do:
When phone want to go sleep or the screen is about to lock, my application receive the "message".
http://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_OFF
You can also use the PowerManager to wake the device up too, which
will prevent screen from lock this time
http://developer.android.com/reference/android/os/PowerManager.html
I am facing a big issue in android service and I searched more than 3 days but I didn't get any solution so please help me.
Currently I am working on a lock screen based service project that make your phone more secure means no one unlock it easily that's work fine but the main problem is that if my application is forced close by user via task manager then it also force close the service of my app then after that, when user press lock button to unlock his phone then it directly open home screen.
Is there any way to restart my application service after few second or at the same time or at the time is user press power button.
In my app I am also disable default lock screen that,s why if my app is force close then after that no security is worked for phone it directly show home screen that's not good, if my app is forced close then at least it enable default lock screen.
Any one who have idea about this please help.
Thanks in advance.
In Android, it's usually not recommended to start the service on it's own even if it is explicitly killed by the user. I don't think if there is a way to start the service again if the user goes into settings and kills it. BTW did you specify the service as remote?