我的嵌套意图服务定义如下:
package com.my.package;... // Bunch of importspublic class MyNotifIEr ... // Bunch of variables public class MissedCallintentService extends IntentService { private static final String TAG = "MissedCallintentService"; public MissedCallintentService() { super("MissedCallintentService"); Log.i(TAG, "Creating intent service."); } @OverrIDe public voID onHandleIntent(Intent intent) { Log.i(TAG, "Handling intent service."); } } // Test my nested intent filter public MyNotifIEr(Context app) { mApp = app; Log.i(LOG_TAG, "Going to start intent service."); Intent intent = new Intent(mApp, MissedCallintentService.class); mApp.startService(intent); } ... // Bunch of functions}
我的AndroIDManifest.xml文件中包含以下内容:
<?xml version="1.0" enCoding="utf-8"?><manifest ...> // Protected broadcasts // Permissions <application ...> <service androID:name="com.my.package.MyNotifIEr.MissedCallintentService" > </service> <activity androID:name="ActivityOne" androID:label="@string/activity_one" <intent-filter> ... </intent-filter> </activity> <activity androID:name="ActivityTwo" androID:label="@string/activity_two" <intent-filter> ... </intent-filter> </activity> <activity androID:name="ActivityThree" androID:label="@string/activity_three" <intent-filter> ... </intent-filter> </activity> </application></manifest>
在构建我的应用程序然后将其推送到手机并运行它之后,这就是我所看到的.
$make_magic && adb remount && adb push MyApp.apk /system/app/ && adb reboot && adb logcat | grep 'intent\ service'make: Leaving directory `BuildDir'remount succeeded6149 KB/s (6036528 bytes in 0.958s)- waiting for device -I/MyNotifIEr( 1184): Going to start intent service.
我应该看到:
I/MyNotifIEr( XXXX): Going to start intent service.I/MissedCallintentService( XXXX): Creating intent service.I/MissedCallintentService( XXXX): Handling intent service.
因此,我的问题点.我需要添加什么才能调用我的意图服务?
解决方法:
将嵌套的内部类声明为静态或在其自己的类中定义它(如果这样做,则更新清单)
如果你引用内部类,引用应该是
<service androID:name="com.my.package.MyNotifIEr$MissedCallintentService" />
(注意美元符号)
总结以上是内存溢出为你收集整理的java – Android:调用Context.startService()后未启动嵌套的Intent服务全部内容,希望文章能够帮你解决java – Android:调用Context.startService()后未启动嵌套的Intent服务所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)