码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-08-27 19:27:45      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

<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问题

标签:

原文地址:http://my.oschina.net/gabriel1215/blog/498262

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!