how does whatsapp service gets restarted even if i force stop app?
Asked Answered
T

4

29

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.

Tuttifrutti answered 28/6, 2012 at 1:43 Comment(1)
I tried this out on Android 4.4.4. I stopped WhatsApp form apps->force stop. After this I did not receive any messages automatically. I had to manually start WhatsApp to get any messages. Does this only happen on 2.3.6 ?Packet
B
49

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.

Bidle answered 28/6, 2012 at 5:55 Comment(9)
Best answer ever! Thanks for the accurate response herom!Tuttifrutti
You're welcome. If this answer was helpful to you, please consider to mark it as the right answer (clicking on the check), so that this question could be marked as closed ;)Bidle
Well , i have implemented GCM but when i closed the service it doesn't receive push notification , so i dont think GCM is helping even if we close the service and still get the mesageWooden
GCM needs available internet connection. You can using any other broadcast receiver such as SMSReceiver for by passing this limitation.Galeiform
actually this is not true because if i implement GCM (Push Notifications) in my app and i kill it i won't receive any push. Actually i think the best way to wake up your app even after has been killed is to register an intent-filter in your manifest, but i don't think it is suitable for this case.Issue
i am not sure if whatsapp is using GCM, since it can run on devices which dont have google apps installedUnstring
@harvey_slash it's a matter of the Android system, which is indeed a Google product, so you need no Google App installed - your operating system is a Google product anyways :) Other than that, my answer is nearly 3 years old now which is a long time for software lifetime and things may have changed since then.Bidle
i can say for sure that GCM will NOT run on android devices that do not have the google appsUnstring
thanks a lot for your investigation - I'm away from Android development for a few years now, so I don't really know what's changed since then. As I stated --> the answer is pretty old now and therefore I added a disclaimer at the top, hope this makes people aware of the age). It may well be that GCM is restricted to phones with Google Apps installed (what's the reason? is there any source you can provide? I'm really curios about the reasons why this is bound to the presence of Google Apps on a device).Bidle
T
13

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.

Towne answered 9/1, 2015 at 9:54 Comment(2)
One of the best solution to agree with.Boar
This solution made my day.Teen
S
2

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.

Sklar answered 9/1, 2015 at 11:33 Comment(1)
START_STICKY not restarting service in lollipop version.. all are workedSanjak
M
1

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

Masinissa answered 14/1, 2015 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.