现在学习一个demo。Activity调用Service,Activity有办法显示Service的数据吗?

解决方案 »

  1.   

    有啊,bindService()就可以和服务端交换数据。不过service的 @Override
    public IBinder onBind(Intent arg0) {
    return mBinder;
    }要反回一个Ibinder的实例。这个你也可以写成AIDL,方便第三方的APK调用。
      

  2.   

    谢谢你。
    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...");

    }
      

  3.   

    Service中的一个参数是Intent,有办法办法通过这个参数,得到调用的Activity的实例呢?
      

  4.   

    service里发送广播 activity接收广播 写字符串?
    不知道楼主是不是这个意思
      

  5.   


    为什么要获取activity的实例呢?你要实现什么需求
      

  6.   

    没法了用Singleton模式交换数据看行不的行
      

  7.   

    可以使用Messenger类来做这个,sdk的doc里面有例子,搜索Remote Messenger Service Sample,
    这个绝对可用,我已经用过了。