进程间bindService失败(魅族手机)

开发中,写了两个应用A、B:

在A中启动了一个MyService,在B中想绑定A的MyService,写法如下:

Intent intent = new Intent();

intent.setPackage("com.test.MyService");

intent.setAction("myaction");

bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);

在华为、小米手机上可正常绑定,但是在魅族手机上无法绑定,经过google和测试,最佳写法如下:

Intent intent= new Intent();

ComponentName componentName= new ComponentName( "com.test", "com.test.MyService" );

intent.setComponent( componentName );

intent.setAction( "myaction" );

bindService( intent, mServiceConn, Context.BIND_AUTO_CREATE);

这么写,就解决问题了。

希望本文能够帮到你。

如果有同学不清楚ComponentName的,推荐看看这篇文章:

http://blog.csdn.net/u012702547/article/details/49557905

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容