允许一个服务被嵌套到一个应用程序? [英] Is a service allowed to be nested into an application?
问题描述
我有我的应用程序做它的应用事情(保存记录,处理单身,等...),我有一个嵌套的服务,将处理套接字连接。我previously在它自己的类有这项服务,但我做到了更加高效,我还以为是将其移动到应用程序是一个好主意。我更新清单:
<服务机器人:名字=$ com.arm.core.ArmApplication IOService的/>
我认为这是声明嵌套服务的正确方法,但我得到一个InstantiationException。服务是否需要是静态的还是我不允许有一个服务被嵌套到另一个类呢?
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):致命异常:主要
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):了java.lang.RuntimeException:无法实例化服务com.android.appion.arm.core.AppionApplication $ IOService的:java.lang.InstantiationException:com.android。 appion.arm.core.AppionApplication $的IOService
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.app.ActivityThread.handleCreateService(ActivityThread.java:3102)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.app.ActivityThread.access $ 3300(ActivityThread.java:135)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2202)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.os.Handler.dispatchMessage(Handler.java:99)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.os.Looper.loop(Looper.java:144)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.app.ActivityThread.main(ActivityThread.java:4937)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在java.lang.reflect.Method.invokeNative(本机方法)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在java.lang.reflect.Method.invoke(Method.java:521)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在dalvik.system.NativeStart.main(本机方法)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):java.lang.InstantiationException:致com.android.appion.arm.core.AppionApplication $的IOService
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在java.lang.Class.newInstanceImpl(本机方法)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在java.lang.Class.newInstance(Class.java:1429)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):在android.app.ActivityThread.handleCreateService(ActivityThread.java:3099)
04-15 14:11:53.167:ERROR / AndroidRuntime(18379):10 ...更多
您必须有一个默认的构造函数。所以,是的,它声明为静态或把它放在它自己的类。
I have my application doing its application things (keeping records, handling singletons, etc...), and I have a nested service that will handle socket connections. I previously had the service in it's own class, but as I made it more efficient, I thought is a good idea to move it into the application. I updated the manifest:
<service android:name="com.arm.core.ArmApplication$IOService"/>
I thought this was the proper method of declaring a nested service, but I get an InstantiationException. Does the service need to be static or am I not allowed to have a service be nested into another class at all?
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): FATAL EXCEPTION: main
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): java.lang.RuntimeException: Unable to instantiate service com.android.appion.arm.core.AppionApplication$IOService: java.lang.InstantiationException: com.android.appion.arm.core.AppionApplication$IOService
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3102)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.app.ActivityThread.access$3300(ActivityThread.java:135)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2202)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.os.Handler.dispatchMessage(Handler.java:99)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.os.Looper.loop(Looper.java:144)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.app.ActivityThread.main(ActivityThread.java:4937)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at java.lang.reflect.Method.invokeNative(Native Method)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at java.lang.reflect.Method.invoke(Method.java:521)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at dalvik.system.NativeStart.main(Native Method)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): Caused by: java.lang.InstantiationException: com.android.appion.arm.core.AppionApplication$IOService
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at java.lang.Class.newInstanceImpl(Native Method)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at java.lang.Class.newInstance(Class.java:1429)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3099)
04-15 14:11:53.167: ERROR/AndroidRuntime(18379): ... 10 more
You must have a default constructor. So yes, declare it as static or put it in it's own class.
这篇关于允许一个服务被嵌套到一个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!