墓志铭制造者 2016-10-29 09:27 采纳率: 66.7%
浏览 3765
已采纳

Android 用Intent 通过action启动Service异常,求帮忙

//定义Intent通过给定的ACTION来启动服务
  Intent intent=new Intent();
        intent.setAction(MyService.ACTION);
        startService(intent);
//service的部分代码
 public class MyService extends Service {
    public static final String ACTION = "com.example.codetest_1.action.startPlayService";
//清单文件
 <service
            android:name=".MyService"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.example.codetest_1.action.startPlayService" />
            </intent-filter>
        </service> 

我实在看不出什么问题了= =一点按钮程序就结束
I/Process: Sending signal. PID: 17843 SIG: 9
Application terminated.

  • 写回答

1条回答 默认 最新

  • SEU_Calvin 博客专家认证 2016-10-29 12:47
    关注

    貌似是5.0以后不允许隐式启动Service,试一下:
    Intent mIntent = new Intent();
    mIntent.setAction(XXX.XXX.XXX);
    mIntent.setPackage(pkgName);//应用的包名
    context.startService(mIntent);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键