首页 / 操作系统 / Linux / Android中activity向service中传值
和activity中互相传值类似这里我是用的intent的,没用广播来,因为本身测试数据量小,就不用之如何启动service?在activity中通过startService(intent)即可,同样intent.putStringExtra()然后再service中的onStart函数中获取该值,this.getIntent(),intent.getString()当然写到这里还是不能传的,不然会报错!!!我们需要在Mainfeist文件中注册这个service<service Android:enabled="true" android:name=".Service"></service>之后就可以自己通过Log或者System.out.println()函数打印也好来测试