Android:调用Context.startService()后无法启动嵌套的Intent服务 [英] Android: Nested Intent Service Not Being Started After Call to Context.startService()

查看:297
本文介绍了Android:调用Context.startService()后无法启动嵌套的Intent服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的嵌套意图服务的定义如下:

My nested intent services is defined as follows:

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文件中包含以下内容:

My AndroidManifest.xml file has the following in it:

<?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>

构建我的应用程序后,将其推送到手机上并运行它,这就是我所看到的.

After building my app then pushing it to the phone and running it this is all I see.

$ 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.

这就是我的问题的重点.我需要添加什么才能调用我的意图服务?

Thus the point of my question. What do I need to add to get my intent service called?

推荐答案

将嵌套的内部类声明为静态或在其自己的类中定义(如果需要,请更新清单)

Declare the nested inner class as static or define it in it's own class (and update the manifest if you do)

如果您引用一个内部类,则引用应为

And if you reference an inner class the reference should be

<service android:name="com.my.package.MyNotifier$MissedCallIntentService" />

(请注意美元符号)

这篇关于Android:调用Context.startService()后无法启动嵌套的Intent服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆