135-1821-9792

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之间传参数
URL标题:http://kswsj.com/article/pdhsee.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号