How to make apps keep running in background to receive notification - android

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 :)

Related

How to send notifications when my app is not running?

I am writing an Android app. I want to send notifications to a device which is not currently running my app. I want to notify what all the new features my app will provide, or when i text something to a person he should be notified about that. How this can be done??
Can we do it with parse.com? If not then what?
Thanx in advance
Yes. You can use Parse Push Notifications for sending messages to devices directly. Another option available would be Google Cloud Messaging. Read more here..
But for all cloud messaging services, you will have to provide a background service which can receive this message and handle it as per requirement. Means, a service will be running in background even when the app is not running in foreground.

How android chat applications (Watsapp, Hangouts, Facebook Messenger etc) are recieving messages even when back ground process stopped manually?

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.

Why gmail/yahoo / what's app service is not getting killed?

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.

Google Cloud Messaging - Will it work when app is not running

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.

Does whatsapp use c2dm aka GCM on android?

I always thought WhatsApp uses c2dm for message delivery. But when I see running apps MessageService is always running. You don't need a service to be run to receive c2dm.
Why keep the service running all the time?
Facebook is even more strange they have 3 services running. One of them is for uploads. Did they start stealing my photos?
Like cached background proccess say - this is an old application proccess that is being kept for better speed in case it is needed again. I suppose, same thing happening with services
WhatsApp uses something like XMPP
WhatsApp uses a customized version of the open standard Extensible Messaging and Presence Protocol (XMPP).
See: http://en.wikipedia.org/wiki/WhatsApp
I'm using GCM myself for a chat application for Android. It's still not working properly if the device is idle for a long time.

Categories

Resources