search

Home  >  Q&A  >  body text

android - 关于startService的一个神奇的问题

  1. 场景:现在写了两个应用AB:

    1

    2

    3

    4

    <code>A : 有一个Service:`com.test.MyService.class`

    B :onClicke点击事件中调起A中的服务。

    测试环境:魅族4,魅蓝3。

    </code>

  2. 问题:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    <code>1)在A程序运行的情况下,B程序运行下,B点击去调起 MyService

    服务,正常。

     

    2)在A程序被杀死的情况下,即没有运行,B程序点击去调起服务,

    不成功,没有任何的Log,Toast输出。

     

    3)在A程序被杀死的情况下,即没有运行,用ADB命令去调起服务:

    不成功,ADB输出,没有找到这个服务。

     

    4)把这个程序A放在/system/app/下,让它成为一个系统的应用,

    然后,在杀死程序的情况下,调起成功。

    </code>

  3. 后续

    1

    2

    3

    4

    5

    6

    <code>公司的大神说,他能直接调起来,不用放在/system/app/下。

    代码我查了好多次,我们两个的代码一样的。然后我注意到一点

    我们的手机系统不同,他的是华为,我的是魅族。

     

    有没有人跟我遇到一样的问题?求大神解释一下咯~

    </code>

PHPzPHPz2926 days ago637

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 09:15:36

    It has been verified that Meizu system does not support the direct awakening of application layer services.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:15:36

    I feel that it is best for your service to be independent in a new process: the service process. There is some mechanism for keeping the service alive or reconnecting. The simplest method is to let onStartCommand return the value START_REDELIVER_INTENT. If a Binder connection is established, Binder also has some reconnection mechanisms. For more ways to stay alive, read online articles, there are many

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:15:36

    I infer that it is an operation performed by the third-party system to prevent wake-up. It can be called natively, otherwise what is the use of the service?

    reply
    0
  • Cancelreply