关于在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都测试可以运行了。。。

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



你可能感兴趣的:(关于在Android5.0中 无法启动Service问题)