跨进程通讯可以通过Intent中附加extras的方式、通过共享文件的方式、通过messenger的方式、通过aidl的方式、通过ContentProvider的方式、通过网络的方式(Socket)。

这里记录通过使用Bundle实现IPC,由于Bundle实现了Parcelable所以它可以方便的在不同进程间传输,Intent可以在Activity、Service和BroadcastReceiver中传递Bundle数据,因此可以通过bundle附件需要传输的信息借助Intent发出去。Bundle支持传输的类型有很多具体可以看其支持的类型,如基本类型、实现了Parcelable或Serializable接口的对象。实例代码如下:

  Bundle bundle = new Bundle();    bundle.putString("test", "来自A");    Intent intent = new Intent(Intent.ACTION_MAIN);    intent.addCategory(Intent.CATEGORY_LAUNCHER);    ComponentName cn = new ComponentName("com.test",            "com.test.MainActivity");//要启动的目标包名和包名+类名    intent.setComponent(cn);    intent.putExtras(bundle);    startActivity(intent);

参考资料:任玉刚《Android开发艺术探索》 刚神csdn地址:https://me.csdn.net/singwhatiwanna

更多相关文章

  1. 详解Android提交数据到服务器的两种方式四种方法
  2. Material Design之TabLayout的用法(标题栏滑动+ViewPager)
  3. Android(安卓)AnimationDrawable运行的几种方式(转)
  4. Android(安卓)模拟按键事件(KeyEvent)
  5. android中开启子线程
  6. Android(安卓)Service 两种启动方式的区别
  7. Android显式intent和隐式intent
  8. Android顶部banner轮播图的两种实现(ViewPager+ViewPagerIndicato
  9. Android(安卓)四大存储方式

随机推荐

  1. Android(安卓)Lint Checks
  2. android 拦截器
  3. Android(安卓)5.0 MaterialDesigh资源整
  4. android studio Error:Execution failed
  5. Google cardBoard Android(安卓)API (十)
  6. Android(安卓)Layout Tricks #2: Reusing
  7. UI overview
  8. API
  9. CheckBox选择按钮,换颜色
  10. padding和margin测试