关于在Android5.0中 无法启动Service问题

<service
            android:name=".MyPushOrderService"
            android:label="@string/app_name"
            android:enabled="true"
            >
<intent-filter>
<!-- 接收到通知后处理的Service -->
<action android:name="com.lanshui.mobile.MYGETPUSH_ORDER_ACTION" />
</intent-filter>
        </service>

以上为在配置文件里配置的service

启动代码:

//启动Service处理任务
                        Intent intent = new Intent();
                        intent.setAction("com.lanshui.mobile.MYGETPUSH_ORDER_ACTION");
                        context.startService(intent);



但是在5.0里怎么都启动不来,弄了半天,结果如下:

去掉配置文件里的配置service

直接启动代码如下:

Intent intent = new Intent(context, MyPushOrderService.class);
                        context.startService(intent);

这就够了。

##########那么问题来了,在4.2.2上又测了下,这下也没法启动Service了。。。

无解,索性将两种方式合并啊。。。新代码如下:

第一步添加注册配置:

<service
            android:name=".MyPushOrderService"
            android:enabled="true"
            android:label="@string/app_name"
            >
            <intent-filter>

                <!-- 接收到通知后处理的Service -->
                <action android:name="com.lanshui.mobile.MYGETPUSH_ORDER_ACTION" />
            </intent-filter>
        </service>



第二部启动方式:

//启动Service处理任务
                        Intent intent = new Intent(context, MyPushOrderService.class);
                        intent.setAction("com.lanshui.mobile.MYGETPUSH_ORDER_ACTION");
                        context.startService(intent);



这下。。。完测啊。。。4.2.2和5.0都测试可以运行了。。。

有更好的方式,请留言哦,继续完善。。。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值