java – Android:调用Context.startService()后未启动嵌套的Intent服务
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Android:调用Context.startService()后未启动嵌套的Intent服务,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2076字,纯文字阅读大概需要3分钟。
内容图文
我的嵌套意图服务定义如下:
package com.my.package;
... // Bunch of imports
public 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 succeeded
6149 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服务所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。