草庐IT

unbindService

全部标签

java - 什么时候应该使用 unbindService(),我应该如何正确使用它来解除与使用 AIDL 接口(interface)的远程服务的绑定(bind)?

我正在编写一个简单的音乐播放器,我已经创建了一个播放服务,它实现了一个AIDL接口(interface)来与客户端绑定(bind),一个是简单的轨道浏览器,另一个是更简单的播放器Activity。该服务控制MediaPlayer对象,而这两个Activity使用ServiceConnections获取与该服务的连接。这包含在两个Activity的onStart()方法中:@OverridepublicvoidonStart(){super.onStart();Intenti=newIntent(this,PureService.class);startService(i);bindSe

android - AdMob: "activity has leaked ServiceConnection"和 "AdvertisingIdClient unbindService failed."

我在我的应用中使用AdMob。我遵循了实现指南,横幅正确显示和加载了广告。我的MainActivity负责创建引用、构建AdRequest和显示横幅,以及暂停、恢复和销毁AdView。每次加载AdRequest时,当调用Activity的onStop()时,会创建以下异常:6706-6706/com.rocca.controlloSpeseE/ActivityThread﹕Activitycom.rocca.controlloSpese.MainActivityhasleakedServiceConnectioncom.google.android.gms.common.b@52b1c

android - AdMob: "activity has leaked ServiceConnection"和 "AdvertisingIdClient unbindService failed."

我在我的应用中使用AdMob。我遵循了实现指南,横幅正确显示和加载了广告。我的MainActivity负责创建引用、构建AdRequest和显示横幅,以及暂停、恢复和销毁AdView。每次加载AdRequest时,当调用Activity的onStop()时,会创建以下异常:6706-6706/com.rocca.controlloSpeseE/ActivityThread﹕Activitycom.rocca.controlloSpese.MainActivityhasleakedServiceConnectioncom.google.android.gms.common.b@52b1c

android - 我需要为 Android 服务调用 unbindService 和 stopService 吗?

在我的Android应用中,我同时调用startService和bindService:Intentintent=newIntent(this,MyService.class);ServiceConnectionconn=newServiceConnection(){...}startService(intent)bindService(intent,conn,BIND_AUTO_CREATE);稍后,我尝试同时unbindService和stopService`:unbindService(conn);stopService(intent);但是,我在调用unbindService时

android - 我需要为 Android 服务调用 unbindService 和 stopService 吗?

在我的Android应用中,我同时调用startService和bindService:Intentintent=newIntent(this,MyService.class);ServiceConnectionconn=newServiceConnection(){...}startService(intent)bindService(intent,conn,BIND_AUTO_CREATE);稍后,我尝试同时unbindService和stopService`:unbindService(conn);stopService(intent);但是,我在调用unbindService时

Android java.lang.IllegalArgumentException : Service not registered

我有一个看起来像这样的设置:classMyFragmentimplementsSomeEventListener{ApplicationmAppContext;booleanmBound;booleanmDidCallUnbind;MyIBindermBinder;ServiceConnectionmConnection=newServiceConnection(){@OverridepublicvoidonServiceConnected(ComponentNamename,IBinderservice){mBound=true;mBinder=(MyIBinder)service;

Android java.lang.IllegalArgumentException : Service not registered

我有一个看起来像这样的设置:classMyFragmentimplementsSomeEventListener{ApplicationmAppContext;booleanmBound;booleanmDidCallUnbind;MyIBindermBinder;ServiceConnectionmConnection=newServiceConnection(){@OverridepublicvoidonServiceConnected(ComponentNamename,IBinderservice){mBound=true;mBinder=(MyIBinder)service;

java - 我需要完美配对 bindService/unbindService 调用吗?

从所有代码示例来看,如果我们调用了#bindService,我们只想调用#unbindService(在同一上下文中),这是通过boolean检查完成的。但是在#bindService调用中没有类似的检查——即我们不检查我们是否已经首先绑定(bind)以避免“双重绑定(bind)”。所以我的问题——如果我多次绑定(bind)一个服务但只解除绑定(bind)一次,“会不会有坏事发生”,或者只有绑定(bind)一次然后解除绑定(bind)多次才不好?这种不对称对我来说似乎很奇怪,但想看看是否有人知道答案。我现在自己正在玩它,试图弄清楚,但更喜欢来自更有经验的开发人员的“官方”答案。什么是“

android - unbindService() 不从服务解除绑定(bind)?

我有一项服务将Messenger存储为成员变量并在onBind(Intent)上返回messenger.getBinder()。我通过以下方式连接到此服务:voidBind(){Intentintent=newIntent("com.example.RemoteBindingService");bindService(intent,mServiceConnection,Context.BIND_AUTO_CREATE);//Context.BIND_AUTO_CREATE//means//"startifnotstarted"mBound=true;}在调用Bind()之前,向服务发送