I have an intent service which is continously polling to check if data has been modified in the server. The problem is if the app remains idle for some time , it stops receiving notification. We are suspecting the service has been killed by android.
I think even GCMINTENTSERVICE is also killed by android in some time.
My question is how come gmail / what's app/yahoo mail always sync without foreground notification. Which sync mechanism they are using.
Are you aware of any other app which is always receiving notification even when in background, so that I can check in Google why it is not killed in some time.
Does Google kill gcmintentservice if it has been running for some time in the backgroud.
EDIT: GCMBASEINTENTSERVICE is the service we are planning to implement for push notifications, because with the older polling service the app did not receive notification after some time. This is may be because it was getting killed by android in some time. So with push notifications, the app will always receive notification? Isn't Gcmbaseintentservice an intent service and that will also be killed by android in some time.
Android will kill services after some time, to resolve memory issues. It's not a good thing to always run your application in background, since it will consume memory and processing power.
You have got the wrong idea. GMail and Yahoo are not polling for new mail, they are using Push Notification mechanism, more precisely Google Cloud Messaging or GCM. Push Notifications can be received in the background, and once they receive a push notification, they sync the app.
BBM (BlackBerry messenger) didn't use GCM, as they relied on BlackBerry servers. So they ran the application in the background without getting killed. This is done by always showing non swipeable notification. Someway with notification, you could run a service in background without getting it killed.
According to AndroidHeadlines
You may want to leave it persistent if you want to use BBM. In Android
4.3, Google has begun fighting apps that suck down battery and stay alive without you knowing. It now requires any app that wants to run
in the background to place a persistent icon in your notification.
Hence the BBM icon. Doing this allows that particular app to never be
closed.
Surely google will kill any service if the device runs out of memory or new services are running in background.
Related
I am working on the voip app. I do all the logic regarding the signaling on background service. When user exists the app I am stoping the service. In this case, I am not connected to the server. When I am in this state, server is sending the push notification (FCM), I am starting the service and creating notification for incoming call or message. This is all good so far:)
I have read about the limitations for Oreo for backgrounding services and realize that now I need to start service in foreground while showing notification. Then I wanted to check how the Hangouts(google) does it, and of course they are running the service in the background when message is received. Am I missing something?
Thank you
Visible activity = foreground
When user exists the app I am stoping the service
If this means that the service is running only when your app is visible to the user, then the process and the service is actually in the foreground and you shouldn't experience any problems with system killing your service:
An app is considered to be in the foreground if any of the following is true:
It has a visible activity, whether the activity is started or paused.
FCM received = foreground
Also, receiving high-priority FCM messages will put your app on temporary whitelist for background processing, and you will have more than enough time to do your processing at that time, or you can always start a foreground service after FCM is received - like a service that handles the call and should display a notification while running:
Under certain circumstances, a background app is placed on a temporary whitelist for several minutes. While an app is on the whitelist, it can launch services without limitation, and its background services are permitted to run. An app is placed on the whitelist when it handles a task that's visible to the user, such as:
Handling a high-priority Firebase Cloud Messaging (FCM) message.
Your app design - handling incoming calls by receiving priority FCM and then creating a foreground call service - seems reasonable.
Refer to the documentation which is really clear on these subjects.
I'm using startForeground to run a service in my app. Does this impact Play Store auto updates when it's running? It seems like it does because I'll release a new version and a test tablet will still be running the old one for days after the release. The app shows "pending update" in Google Play on the device.
As background, this is not a normal consumer app and does need to run all the time to sync data. Without the foreground service I found even persistent alarms would stop running in a timely fashion after a few days, so as far as I'm aware, startForeground is the only way to keep the app running permanently.
Thanks for reading!
You can create an application which the Android system puts under whitelist application.
Under certain circumstances, a background app is placed on a temporary whitelist for several minutes. While an app is on the whitelist, it can launch services without limitation, and its background services are permitted to run.
An app is placed on the whitelist when it handles a task that's visible to the user, such as:
Handling a high-priority Firebase Cloud Messaging (FCM) message.
Receiving a broadcast, such as an SMS/MMS message.
Executing a PendingIntent from a notification.
Starting a VpnService before the VPN app promotes itself to the
foreground.
So you can create a high-priority FCM message for your update and send it as an update notification or just a blank message.
Set Up a Firebase Cloud Messaging Client App on Android
I am trying to implement an Android chat application using web-socket.
I am using an Android service to connect to the web socket server. It is working fine, but when I force stop the service (Not the application) manually in task manager
(Settings -> Apps -> Running)
Then my application is not receiving any messages from server. What I observe from other chat applications is even if I stop the background services of those applications, they are receiving messages and after some time the services also automatically started. How is it possible? Is there any other hidden service that wakes up the main application thread?
You can force start the service every time it is force stopped
Take a look at this (How to automatically restart a service even if user force close it?)
Most of those apps are using a push service such as Google Cloud Messaging.
Continually polling servers or maintaining a persistent web socket is not a resource-friendly method of receiving messages from a server over an extended period of time.
To my knowledge, they do not have a special way of doing this. They may have "work arounds" that are convenient (for example, Facebook Messenger can wake the FB app, if you have both installed and stop only 1 of them).
As of Android 3.1, an app cannot wake itself and GCM also will not wake it. See here: GCM push notifications on android 3.1 : disable broadcast receiver
CommonsWare usually knows what he's talking about. Also, I have tested it and it doesn't work for me on the 3.1+ APIs.
I'm developing a messaging application and I need my service to keep running in background even if the application was closed but without showing a notification in navigation bar and start when the phone is started and restart itself when it is closed for any reason, I know this question has been asked before but I can find nothing to do this, I just want it to be like whatsapp or facebook or bbm services, thanks in advance.
I need my service to keep running in background even if the application was closed but without showing a notification in navigation bar and start when the phone is started and restart itself when it is closed for any reason
That is not strictly possible.
You are welcome to return START_STICKY or START_REDELIVER_INTENT from your service's onStartCommand() method. Android will still terminate your process due to old age and low memory conditions from time to time, but Android will eventually restart those services. What percentage of the time your process will be running will depend on a variety of factors, not the least of which being how much system RAM the Android device has.
Better yet, you are welcome to use Google Cloud Messaging (GCM) to deliver your messages to your app. This way, you do not need a service running all of the time. Your app can get control when a message arrives, do some work for that message, then go away.
I just want it to be like whatsapp or facebook or bbm services
BlackBerry Messenger uses startForeground() and has an icon in the status bar as a result.
I have implemented Parse notification in my app. I have put the initialization call in the app.onCreate().
When the app is running, it works perfectly. However, if the app is killed, I find that the notifications are not coming through.
Has anyone seen this?
If the app is force stopped, Google Cloud Messaging won't work until the app is launched again by the user. That's the behavior since Android 3+ (don't remember the exact version).
If the app runs in the background or is stopped implicitly by the OS (to free memory), GCM will work.
Parse push notifications would behave the same, since they use GCM.