I always used Android 2.2 for my Apps. But currently I upgraded to Android 2.3.X Gingerbread. So if I start my App and go back to the android "desktop", the app is kill by 3-4 Minutes.
I think it will be killed after some minutes inactivity, but I need to run it in background to read some mobile status.
How can I set my App as a "Background" App, so that Android will not longer kill it?
Thanks for Help...
Regards, Rookee
To run an application in the background it must be of type "Service". You have to register a service and it will run in your device forever. For more info, Android Services
Related
When I used foreground service then when I kill the application then foreground service is automatically killed but I want to alive foreground service when the application is killed. this issue appeared in android 10 and android 11. how to solve this issue.
You can't do that as you should not be able to keep alive a foreground service after the application is killed.
You should only use a foreground service when your app needs to perform a task that is noticeable by the user even when they're not directly interacting with the app. If the action is of low enough importance that you want to use a minimum-priority notification, create a background task instead.
If you what to have some background service working, that will be possible.
You can find some useful information here :
https://developer.android.com/guide/components/foreground-services
https://developer.android.com/training/run-background-service/create-service
It should not get killed. When starting foreground service you need to create notification too. You have done that, right?
If you done everything right there is possibility that you have xiaomi phone. Xiaomi deletes everything when app killed. You need to add specific intent protection...
I create background and foreground service both to get android location on every Interval and send it to server.
When App is in foreground at that time service run fine but when app is in background my foreground service notification display perfect for few minutes after some time it automatically killed my service and I am not getting any location update after that.
It runs fine in Samsung device but create issue in Oppo,Vivo, Mi and OnePlus device
So please help me out to find best way to run Location service when app is closed, background or foreground in any state in all device and Android version greater Than "O"
Thanks in Advance
I am trying to create a locker application to show pin view when the user enters to defended application. I created a service that runs and tracks the current foreground application. However, on devices with android version 10 activity is not starting from my service. I know that from android 10 there are restrictions to start an activity from the background, however, there are exceptions either. The activity can start from the background when the application is in the foreground, but it won't help in my case. So the question is how can I start the activity from service to show pin view?
P.s: I tried it with window manager but again in higher android versions there is an annoying notification that can open settings do dismiss overlay permission. Also, I saw a working "app locker" application in the play store, so I believe there is a way.
From android 10 foreground service will work only if u start the service while the app is in foreground. If your app is in background you will need background location permission which has to be requested separate after you gain permission for coarse and fine location. Also if your app is in testing mode and not in Play Store and u update your device to android 10 a fresh install of the app is needed.
There is no point in using a foreground service if u want to start that service from background. Just get background location and stop using foreground service.
IN bound service when I lock the device after the 70- 80 seconds service stops I am testing on realme 3 pro and one plus 5 both having API 9 PIE. How to keep service running until the app is in recent activity. Even foreground services are also stopped. Thanks in advance.
Realme, Oneplus, Samsung, Xiaomi, Huawei and a few other manufacturers have their own layer of "Battery Saver" or "Security" that kills or restricts background running apps in order to improve security/battery backup, unless user white-lists your app in the relevant device settings.
What i found out about Xiaomi is that they white-list well known apps like Facebook, Whatsapp, etc. But you cannot request Xiaomi to white-list your app.
These manufacturer apps simply terminate your app process. So your app should behave in such a way that termination at any moment should not create inconsistent state.
Also, you can always show a popup to user after installation asking him/her to go and white-list your app in battery saver. In Xiaomi, the user will need to select 'Do not restrict background activity' and also enable 'Auto Start' for your app. As far as i know, there is no other solution.
Conclusion: Visit https://dontkillmyapp.com and see how the apps are whitelisted for your OEM. Once whitelisted, it will work as expected.
But out there in real world, it will get killed and users won't manually whitelist it.
Custom Roms have it's own security apps and it close the app service when u remove it from recent or after few minutes.
To keep running your app in background you have to enable autoStart from settings
Refer this : How to fix the issue that the activity is killed automatically after some minutes in newly version as like vivo and oppo
Facing same issue from long time, Try to add FCM in your application and start service from it directly or else set alarm and startservice.
In some cases above solution work. i have added above solution in 4 project but succeed in only 1.
Issues which I have found while overcoming problem with firebase.
Firebase Notification coming to app but Background service not starting
Firebase Notification Not coming to application
Firebase Notification coming and service starting with Broadcast Receiver (Sometimes
service not starting directly from onMessageReceived() method of Firebase so i
decided to set broadcast Receiver ) but sometime its stop working.
Issue which I have found without implementing Firebase
If we set background service to run after every 5 mins than for 1-2 hours its
running on 5 mins interval but after 2 hours time gap increased and service runs on
15 mins of interval and in some devices its run on 20-30 mins of interval(i found
this in right time because phone may goes in ideal mode).
As mention in your question, sometimes any of above implementation doesn't work.
Tip : What I found in system alarm log ?
I have set alarm for 2019-08-08
11:07:00 which not fired and current time is 2019-08-08 11:10:00 but its showing in
pending in system alarm log.
You can check system all Alarm set by your applications
D:\SDK\platform-tools>adb shell dumpsys alarm
Want to run a service in back ground when SMS or call received then background service call the flash on and off. Application works on marshmallow and low version. But not work on Oreo 8.0 and Pie 9.0. Due to Background service application crash after 10 second when application open.
Android.app.RemoteServiceException: Context.startForegroundService()
did not then call Service.startForeground()
How we fix this issue?
You have to call "Service.startForeground()" within few seconds after called "startForegroundService()" or the Service will be killed by Android.
Changes from Android 8: https://developer.android.com/about/versions/oreo/android-8.0-changes