请教个问题,Activity调用Service,Service有办法在Activity界面写字符串吗? 现在学习一个demo。Activity调用Service,Activity有办法显示Service的数据吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有啊,bindService()就可以和服务端交换数据。不过service的 @Override public IBinder onBind(Intent arg0) { return mBinder; }要反回一个Ibinder的实例。这个你也可以写成AIDL,方便第三方的APK调用。 谢谢你。Activity中的代码是这样的: private void doStart() { Intent startService = new Intent(this, DummyService.class); this.startService(startService); }Service中的代码是这样的:@Override public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub super.onStart(intent, startId); Toast.makeText(this, "I'm a service!", Toast.LENGTH_LONG).show(); Log.d(getClass().getName(), "Service starting..."); } Service中的一个参数是Intent,有办法办法通过这个参数,得到调用的Activity的实例呢? service里发送广播 activity接收广播 写字符串?不知道楼主是不是这个意思 为什么要获取activity的实例呢?你要实现什么需求 没法了用Singleton模式交换数据看行不的行 可以使用Messenger类来做这个,sdk的doc里面有例子,搜索Remote Messenger Service Sample,这个绝对可用,我已经用过了。 新人求助,请各位前辈帮我看看错误在哪里 从log中截的一段,求大神知道错误在哪 本人正在做一个电子书阅读器,想知道如何实现按章节分割大的txt文件 ndk编译skia静态库 谈谈我的android应用面向市场的经历 【android文件读取问题】 安卓sd卡上创建文件夹失败,求解答 开发中关于日志的输出和过滤 android 华为手机导航栏影响界面布局 Android 连接指定WIFI问题 Android获取地理位置的程序 关于Android驱动测试的问题1
public IBinder onBind(Intent arg0) {
return mBinder;
}要反回一个Ibinder的实例。这个你也可以写成AIDL,方便第三方的APK调用。
Activity中的代码是这样的:
private void doStart() {
Intent startService = new Intent(this, DummyService.class);
this.startService(startService);
}Service中的代码是这样的:
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Toast.makeText(this, "I'm a service!", Toast.LENGTH_LONG).show();
Log.d(getClass().getName(), "Service starting...");
}
不知道楼主是不是这个意思
为什么要获取activity的实例呢?你要实现什么需求
这个绝对可用,我已经用过了。