本文介绍了bindService方法后onServiceConnected从来没有所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特殊的情况:由广播接收器启动的服务启动的活动。我想,这使本次活动的通信回服务。我选择使用AIDL,使之成为可能。一切似乎都工作良好,除了 bindService()方法调用的onCreate()的活动。 bindService(),其实,抛出一个空指针异常,因为 onServiceConnected()永远不会被调用,而 onBind()方法该服务是。反正 bindService()返回true。因为它启动活动的服务是明显活性。我知道,从一个服务调用的活动可能听起来很奇怪,但不幸的是这是在服务的语音识别的唯一途径。

I have a particular situation:a service started by a broadcast receiver starts an activity. I want to make it possible for this activity to communicate back to the service. I have chosen to use AIDL to make it possible. Everything seems works good except for bindService() method called in onCreate() of the activity. bindService(), in fact, throws a null pointer exception because onServiceConnected() is never called while onBind() method of the service is. Anyway bindService() returns true. The service is obviously active because it starts the activity.I know that calling an activity from a service could sound strange, but unfortunately this is the only way to have speech recognition in a service.

在此先感谢

推荐答案

我无法弥补确切的问题出你的描述,所以我要在这里猜!

I can't make up the exact problem out of your description, so I'm going to guess here!

如何 bindService()抛出一个 NullPointerException异常?这可能(/应)发生的唯一方法是,当你不提供服务 ServiceConnection 监听器。

How can bindService() throw a NullPointerException? The only way this could (/should) happen is when you don't supply a Service or a ServiceConnection listener.

bindService()不能把一个 NullPointerException异常 ,因为 onServiceConnected()不叫。以 onServiceConnected()通话是产品 bindService()

bindService() can't throw a NullPointerException because onServiceConnected() isn't called. The call to onServiceConnected() is a product of bindService().

所以我猜你调用一个 AIDL 法,服务之前实际上保税?

So I guess you are calling a AIDL method, before the Service has actually bonded?

这篇关于bindService方法后onServiceConnected从来没有所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 01:23