Keep android application open - android

On the Android Market there is an app called Sleep Timer, and it is a type of alarm clock that brings runs the alarm even though you locked your phone while on facebook. I made a type of app that detects movement however it only works if the phone is left on that app... How can I make it work when the app wasn't left upfront, but is still running in the background?

You should take a look at Android Services, which provide the functionality you seek. Basically they enable you to create components that run in the background even when the user switch away from your application.
You can find a very good introduction to them here: http://developer.android.com/guide/components/services.html

Related

Flutter app stay running while in background

I have an app I have building that is giving navigation from a location to a location. Contstantly tracking where the user is using GPS data in order to give good Directional information. Currently if a user switches from our app to another app or goes to the Android home screen, after one minute Android turns off our app for performance reasons.
I have tried using an Isolate but like flutter this gets shutdown. Next step were to use a kotlin service to handle background things but i wanted to check if anyone had done this in dart yet?
Also this is not an app that will be in the play store or on public devices. It is going on special devices that we control and are less worried about memory usage as this will be the main app ran on them.
as mentioned above in the comment by #galloper background_fetch is the thing you need, it has a method called BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); where backgroundFetchHeadlessTask is a function that will keep running even when the app is close, i used this in my app to stream location info to server.

Prevent my app to sleep when device goes to sleep mode

I have written an app that should be running continually event if device goes to sleep mode.I have tried many things like services (with startForground also) , alarm manager and persistant="true", but when device go to sleep (by user or by device) , my app is terminated.and even PowerManager does not work too.
There is an option in device setting that is 'Keep running after screen off' (in huawei device : setting > app > my app options > battery > Keep running after screen off). So when this option is active , the app is running for ever.I want implement something like this in my app programitically.
I saw some apps that implemented this , but I dont know how.
So how can I do that?
Use ForgroundService.
If you check your device applications with an app manager, you can see that some of them using a sevice that is always running. even if you stop them, some of them start working again.
see more about services behavior in android developer.
and search for "keeping a service alive".
On some devices (Huawei, Xiaomi, LG) there is a special setting that contains a list of apps that are allowed to run in the background. It sounds like you are talking about trying to accomplish the same thing. This cannot be done on those devices. On those devices, unless your app is added to the list of apps that are allowed to run in the background ("Protected Apps" on Huawei), the Android framework will not restart your app if it is shutdown. There is no way for you to programatically add your app to this list, and there is no way for you to work around this feature.
Certain apps need to keep the screen turned on, such as games or movie apps. The best way to do this is to use the FLAG_KEEP_SCREEN_ON in your activity (and only in an activity, never in a service or other app component).
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Does disconnecting Android Phone Display Hardware Stop Apps

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.

Cordova - detect that app is in the background

I have a feature in my cordova app that lets user do something when user shakes the phone (I'm using shake.js for the purpose). The phone vibrates when it happens.
The problem is that, when I "alt tab" away from the app and it's in the background, the shake/vibrate combo still works. So the user might be using a completely different app and the phone would still vibrate.
Is there a way to detect that the app is in the background, or better yet, freeze the app somehow when it's going to the background?
I have this problem on Android (haven't tested it on iOS yet).
You can simply bind the pause event and you remove the shake feature from your app.
According to the documentation The (pause) event fires when an application is put into the background.
You can listen for the resume event to put back the shake feature.
As usual in the documentation you can find complete code examples.

How to lock any android application

I am a newbie on android apps development, I want to make a application which can lock any application when started. For eg if someone opens chrome or any other application it simply locks it.
Maybe you will not get any straight forward solution for that.you have to create a service that will run on the background.You can check periodically to find therunning process.Then you can find the package name for the process which you want to kill.Finally use killBackgroundProcess of the ActivityManager to kill the process.This method only kill background process.So if you want to stop browser that starts running simply send that in background(If you bring your activity in foreground it automatically will be back) and run the killBackgroundProcess(pkgName).
Android now allows users to add app widgets to the lock screen form API level 17, i dont know backward comparability supports or not

Categories

Resources