I have looked on similar threads however couldn't find a definitive answer.
For android 3.1+, if an app is force killed it doesn't receive broadcasts.
Force killed stops all running services and proccesses.
Does this mean if my app doesn't have a running service and is swiped out of recent apps then it will not receive GCM notifications?
Or does this only apply to when the force stop button is actually pressed.
Maybe you know the (deprecated) version of GCM. There we had to implement a WakefulBroadcastReceiver service which was started automatically when reveicing any GCM notification. This service had to "wake up" your app and in turn is able to start any of your own services.
This of course is still valid for the most recent GCM API-version but there you have to extend GcmListenerService which also is called by a WakefulBroadcastReceiver.
For detailed information on how to implement this please refer to Google's code sample.
To say it short - yes it will work if it is implemented correctly.
Related
Hi guys how to make my apps running in background so that it can receive notification although the apps being cleared by RAM clearing feature in our phone?
Try to read about a services and/or about GCM. For the notifications GCM is a good choice for Android.
Useful links:
1): Service
2) GCM(Google Cloud Messaging)
You need a Service to make your app run in background even if the app has been killed.
You need a BroadcastReceiver to start the service when the device boots up.
How to implement it?
Hope it helps :)
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 am using geofence service in my app and using exactly the same sample as given in the google documentation.
Doing some research i found that the Intent service is killed when the app is killed. I want to receive the geofence notifications even when the app is not running. How can i do that.?
I have looked for the examples using broadcast receivers but they are old and use classes which are deprecated.
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.
I am running whatsapp (we could call it appX from now on) in device A. I go to manage applications -> force close so appX gets closed and i no longer see appX as running services.
Now, after 5 minutes, I send a message from another device 's appX (device B) to device A appX (the one we killed it).
Here are the 2 scenarios i tested :
device A with android 2.1 : it never receives the message, therefore we could say that none of appX services got restarted. It ONLY receives the message if manually the user restarts the app.
device A with android 2.3.6 : for SOME magic reason, no matter how long it's been since appX got killed, as soon as we send the message from device B -> device A gets the message, therefore, appX's service gets restarted. Note : all the time that appX was closed and WITHOUT receiving any notification, i wasn't able to see any running services of appX in manage applications, so this means that this magic service gets restarted as soon as it receives a message/notification
I know it sounds weird, and lot of people will say this is impossible, but again, this has been tested on these 2 devices.
I am trying to accomplish this same behavior, so any help will be appreciated it.
I don't think it's some magic what happens here! It's just Android C2DM (see: https://developers.google.com/android/c2dm/), whereas the app has a registered Receiver for incoming Push Notifications and gets awaken by this message.
Android C2DM is/was available with Android 2.2, that's the reason why you can't see the same behaviour on your device with Android 2.1 up and running.
By the way: As you can see, C2DM is deprecated since June 26th, 2012. So instead of C2DM, one should use GCM (see: http://developer.android.com/guide/google/gcm/gs.html)
Useful Comment: GCM needs available internet connection. You can using any other broadcast receiver such as SMSReceiver for by passing this limitation.
Starting from Android 3.1 (API 12), if an application is force-stopped it will not restart until the user manually runs the app again.
This will happen even if the app contains a Service or an active BroadcastReceiver.
You can find the official documentation here.
i dont have idea about whatsApp service.
But it is possible that after force stop application, restart service of app.
i use START_STICKY service for my chatApp. i have to do same thing so i use START_STICKY service so when my app kill or force stop from setting, after few second my service get restart and i able to login to my xmpp server and get incoming message.
its nothing magical here appX uses push notifications via android GCM platform https://developer.android.com/google/gcm/index.html in GCM the app registers for a braodcast reciever and the broadcast receiver starts the service on getting the push notification.
Android GCM is dependent on google play services that are available on android 2.2 and beyond that therefore you didn't see the message on 2.1 device