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.
Related
I have noticed that when I send a push notification (Firebase Messaging Service) to my device my Application object is created. This is without clicking on the notification. Simply the act of viewing the notification creates the application. Further, it also starts the Jetpack AppStartup library. I want to be able to use AppStartup and application create. But I don't want to launch that code when a push notification occurs.
Why does Android do this? Is this part of all android notification, or is it a feature of the third-party push notification sdk I am using? And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
Again, I'm not talking about the user clicking on the notification (and launching the app because of a deeplink). I'm talking about just looking at the notification in the notification dropdown.
Why does Android do this?
Android is starting your app process to run code in your app. Creating an Application instance and calling onCreate() will be part of that, as will creating any ContentProvider objects. IIRC, Jetpack Startup uses a ContentProvider to get control early in your process, though I am not 100% certain of that.
The reason why Android is starting your app process is because your app is causing the Notification to be displayed — specifically, Firebase Cloud Messaging is doing that. If I remember the protocol correctly, Play Services is sending a broadcast Intent that Firebase Cloud Messaging in your app will respond to, and part of that code will be displaying the Notification.
And is there a way in Application.create and AppStartup to distinguish a normal app launch from a push notification triggered launch?
onCreate() of an Application subclass has no means of knowing what specifically caused the process to be created, as there can be many possible reasons. If by "AppStartup" you mean Jetpack Startup, I do not recall it having any options here, but I have not spent much time with its API.
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'm developing viber like application using the ionic framework.
I want my app to be able to receive calls even when its on the background, just like whatsapp, the incoming call screen will pop up even if whatsapp is on the background or even when there is no instance of it at all.
I wasn't able to find anything about it.
I'm afraid there's no other way to achive this, then using Google Cloud Messaging (GCM). Although there may be other services that do the same.
When using GCM, your app will be notified with a notification even if it is not running.
But be careful! As your using Ionic, you will most likely rely on a cordova plugin to receive the notifications that are pushed to your device via GCM.
It depends on the chosen plugin how it handles the incoming notification.
I have used GCM to get push notifications, now if I Force stop the app from the settings on the Android device, will it be able to get push notifications?
I have read many posts that say in this case an app cannot receive notifications.
Is there any possibility to get notifications?
Once you force-stop your app from Settings, your code will not run until something manually runs one of your components (ie the user manually launches an activity).
Therefore after force-stopping your app from Settings, you will not receive GCM messages.
If you want to get notifications you have to manually restart your app.
This is by design since Android 3.1.
Apps that are in the stopped state do not receive broadcast Intents.
Stopped state is:
when the app is initially installed (before the user runs something in
the app) or
after a Force Stop.
You can find more about this here: http://developer.android.com/about/versions/android-3.1.html#launchcontrols
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