即使我强制停止应用程序,whatsapp服务如何重新启动?

时间:2021-12-24 02:12:23

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.

我在设备A中运行whatsapp(我们可以从现在开始称它为appX)。我去管理应用程序 - >强制关闭以便appX关闭,我不再将appX视为正在运行的服务。

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 :

现在,5分钟后,我从另一台设备的appX(设备B)向设备A appX(我们杀死它的那个)发送消息。以下是我测试的两个场景:

  • 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.

    设备A与Android 2.1:它永远不会收到消息,因此我们可以说没有任何appX服务重新启动。如果手动用户重新启动应用程序,它仅接收消息。

  • 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

    设备A与android 2.3.6:出于一些神奇的原因,无论自appX被杀多久以来,只要我们从设备B发送消息 - >设备A获取消息,因此,appX的服务重新启动。注意:在关闭appX并且没有收到任何通知的情况下,我无法在管理应用程序中看到appX的任何正在运行的服务,因此这意味着一旦收到消息/通知,这个魔术服务就会重新启动

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.

我试图完成同样的行为,所以任何帮助将不胜感激。

4 个解决方案

#1


46  

Before you up/down-vote this answer please take into account that the answer is nearly 3 years old now (speaking of May 2015) and things may have changed!

在您对此答案进行上/下投票之前,请考虑到现在答案已接近3年(谈到2015年5月),事情可能已经发生变化!

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.

我觉得这里发生的事情并不神奇!它只是Android C2DM(请参阅:https://developers.google.com/android/c2dm/),而应用程序有一个注册的Receiver用于传入推送通知,并被此消息唤醒。 Android C2可用于Android 2.2,这就是为什么在Android 2.1启动并运行的情况下,您无法在设备上看到相同的行为。

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)

顺便说一句:正如您所看到的,C2DM自2012年6月26日起被弃用。因此,不应使用C2DM,而应使用GCM(请参阅: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.

有用的评论:GCM需要可用的互联网连接。您可以通过此限制使用任何其他广播接收器,如SMSReceiver。

#2


12  

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.

从Android 3.1(API 12)开始,如果应用程序被强制停止,则在用户再次手动运行应用程序之前,它不会重新启动。

This will happen even if the app contains a Service or an active BroadcastReceiver.

即使应用程序包含服务或活动的BroadcastReceiver,也会发生这种情况。

You can find the official documentation here.

你可以在这里找到官方文档。

#3


2  

i dont have idea about whatsApp service.

我不知道whatsApp服务。

But it is possible that after force stop application, restart service of app.

但是有可能在强制停止应用后,重启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.

我为我的chatApp使用START_STICKY服务。我必须做同样的事情,所以我使用START_STICKY服务,所以当我的应用程序杀死或强制停止设置,几秒后我的服务重新启动,我能够登录到我的xmpp服务器并获取传入消息。

#4


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

这里没什么神奇的appX使用推送通知通过Android GCM平台https://developer.android.com/google/gcm/index.html在GCM中应用程序注册一个braodcast接收器,广播接收器启动服务获取推送通知。 Android GCM依赖于Android 2.2及更高版本上提供的Google Play服务,因此您在2.1设备上看不到该消息

#1


46  

Before you up/down-vote this answer please take into account that the answer is nearly 3 years old now (speaking of May 2015) and things may have changed!

在您对此答案进行上/下投票之前,请考虑到现在答案已接近3年(谈到2015年5月),事情可能已经发生变化!

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.

我觉得这里发生的事情并不神奇!它只是Android C2DM(请参阅:https://developers.google.com/android/c2dm/),而应用程序有一个注册的Receiver用于传入推送通知,并被此消息唤醒。 Android C2可用于Android 2.2,这就是为什么在Android 2.1启动并运行的情况下,您无法在设备上看到相同的行为。

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)

顺便说一句:正如您所看到的,C2DM自2012年6月26日起被弃用。因此,不应使用C2DM,而应使用GCM(请参阅: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.

有用的评论:GCM需要可用的互联网连接。您可以通过此限制使用任何其他广播接收器,如SMSReceiver。

#2


12  

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.

从Android 3.1(API 12)开始,如果应用程序被强制停止,则在用户再次手动运行应用程序之前,它不会重新启动。

This will happen even if the app contains a Service or an active BroadcastReceiver.

即使应用程序包含服务或活动的BroadcastReceiver,也会发生这种情况。

You can find the official documentation here.

你可以在这里找到官方文档。

#3


2  

i dont have idea about whatsApp service.

我不知道whatsApp服务。

But it is possible that after force stop application, restart service of app.

但是有可能在强制停止应用后,重启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.

我为我的chatApp使用START_STICKY服务。我必须做同样的事情,所以我使用START_STICKY服务,所以当我的应用程序杀死或强制停止设置,几秒后我的服务重新启动,我能够登录到我的xmpp服务器并获取传入消息。

#4


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

这里没什么神奇的appX使用推送通知通过Android GCM平台https://developer.android.com/google/gcm/index.html在GCM中应用程序注册一个braodcast接收器,广播接收器启动服务获取推送通知。 Android GCM依赖于Android 2.2及更高版本上提供的Google Play服务,因此您在2.1设备上看不到该消息