草庐IT

ServiceConnection

全部标签

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;

android - 如何自行停止服务?

我在Activity中启动服务,然后我希望服务在一段时间后自行停止。我在服务中调用了stopSelf()但它不起作用。如何让服务自行停止? 最佳答案 说“不起作用”,我猜你的意思是服务的onDestroy()方法没有被调用。我遇到了同样的问题,因为我bound一些ServiceConnection使用标志BIND_AUTO_CREATE到服务本身.这会导致服务一直保持Activity状态,直到每个连接都为unbound。.一旦我更改为不使用标志(零),我就可以自行终止服务(stopSelf())。示例代码:finalContexta

android - 如何自行停止服务?

我在Activity中启动服务,然后我希望服务在一段时间后自行停止。我在服务中调用了stopSelf()但它不起作用。如何让服务自行停止? 最佳答案 说“不起作用”,我猜你的意思是服务的onDestroy()方法没有被调用。我遇到了同样的问题,因为我bound一些ServiceConnection使用标志BIND_AUTO_CREATE到服务本身.这会导致服务一直保持Activity状态,直到每个连接都为unbound。.一旦我更改为不使用标志(零),我就可以自行终止服务(stopSelf())。示例代码:finalContexta

java - Android Context.bindService 总是返回 false 并且永远不会触发 ServiceConnection 对象

我关注了LocalServiceexample由Google提供,但我的Context::bindService(...)总是返回false并且也从未调用过ServiceConnection::onServiceConnected。我知道Context::bindService()会立即返回,但我的ServiceConnection对象永远不会被触发。我不知道这些是否适用我的Activity在tabHost中运行,我想知道这是否会以任何方式影响服务绑定(bind)。服务本身可能有问题,但我可以使用相同的Intent将启动服务调用到相同的服务,它可以按预期工作。有人有这方面的经验吗?请帮

java - Android Context.bindService 总是返回 false 并且永远不会触发 ServiceConnection 对象

我关注了LocalServiceexample由Google提供,但我的Context::bindService(...)总是返回false并且也从未调用过ServiceConnection::onServiceConnected。我知道Context::bindService()会立即返回,但我的ServiceConnection对象永远不会被触发。我不知道这些是否适用我的Activity在tabHost中运行,我想知道这是否会以任何方式影响服务绑定(bind)。服务本身可能有问题,但我可以使用相同的Intent将启动服务调用到相同的服务,它可以按预期工作。有人有这方面的经验吗?请帮

android - 每个服务绑定(bind)是否需要一个 ServiceConnection?

我有几个AndroidService,我想在我的Activity中绑定(bind)它们,因此我可以监视用户的多个操作。为了能够绑定(bind)每个服务,我将有多个服务,我是否需要在我的Activity中使用多个私有(private)ServiceConnection,如下所示?/**Definescallbacksforservicebinding,passedtobindService()*/privateServiceConnectionmConnection=newServiceConnection(){@OverridepublicvoidonServiceConnected(