androidActivity和Service之间传参数

在 Activity中

创新互联建站-专业网站定制、快速模板网站建设、高性价比阳江网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式阳江网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖阳江地区。费用合理售后完善,10余年实体公司更值得信赖。

Intent intent = new Intent();

intent.setAction("jingbao_Service");

intent.putExtra("flag", true);

startService(intent);

在Service中

public int onStartCommand(Intent intent, int flags, int startID){

Log.v(null, "onStartCommand");

//intent = new Intent();

Bundle bundle = intent.getExtras();

boolean flag = bundle.getBoolean("flag");

if(flag == true){

musicStart();

}else{

musicStop();

}

return START_STICKY;

}

这里需要说明的是 需要在onStartCommand()方法中接收数据

我原来在onCreate中接收 出现了 NullPoint 异常



当前名称:androidActivity和Service之间传参数
本文地址:http://lszwz.com/article/pdhsee.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款