意图服务从未开始

时间:2013-06-08 07:30:20

标签: android android-intent service android-service

我正在创建我的第一个intent service,我已经按照this教程但由于某种原因我的意图服务永远不会启动。我试图从片段中调用intentService。这是片段的onCreate代码:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
        .....

        IntentFilter filter = new IntentFilter(ResponseReceiver.ACTION_RESP);
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        receiver = new ResponseReceiver();
        getActivity().registerReceiver(receiver, filter);

        return homeSalePage;
    }

现在从intentService函数的某些AsyncTask调用onPostExecute的开始,这里是代码:

        Intent msgIntent = new Intent(getActivity(), SaleServiceForImages.class);
        Bundle b = new Bundle();
        b.putString("saleId", "H7m2F4zdT6");
        b.putInt("rowId", 1);
        msgIntent.putExtras(b);
        getActivity().startService(msgIntent);

SaleServiceForImages

    public class SaleServiceForImages extends IntentService 
    {
        public SaleServiceForImages() 
        {
            super("SaleServiceForImages");
        }

        @Override
        protected void onHandleIntent(Intent intent) 
        {
            Intent broadcastIntent = new Intent();
            broadcastIntent.setAction(ResponseReceiver.ACTION_RESP);
            broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
            ImgService imgService = new ImgService();
            Bundle b = intent.getExtras();
            Bitmap bitmap = imgService.getImageOfSale(b.getString("saleId"));
            broadcastIntent.putExtra("BitmapImage", bitmap);
            broadcastIntent.putExtras(b);
            sendBroadcast(broadcastIntent);
        }
    }

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.shale.shaleapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:resizeable="true"
        android:smallScreens="true" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    <application
        android:allowBackup="true"
        android:name="com.shale.activities.GlobalActivity"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
        <activity
            android:name="com.shale.activities.SplashActivity"
            android:label="@string/app_name"
            android:configChanges="orientation"
            android:screenOrientation="portrait"
            android:noHistory="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.shale.activities.MainActivity"
            android:label="@string/app_name"
            android:configChanges="orientation"
            android:screenOrientation="portrait"
            android:noHistory="true" >
        </activity>
        <activity
            android:name="com.shale.activities.MainPage"
            android:label="@string/title_activity_main_page"
            android:configChanges="orientation"
            android:screenOrientation="portrait" >
        </activity>

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/fb_app_id" />
        <activity
            android:name="com.facebook.LoginActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="com.shale.activities.SearchActivity"
            android:label="@string/title_activity_search" >
        </activity>
        <activity
            android:name="com.shale.activities.ShareSaleActivity"
            android:label="@string/title_activity_share_sale" >
        </activity>

        <service android:enabled="true"  
         android:name="com.shale.services.SaleServiceForImages" />
    </application>

</manifest>

不知道从哪里开始查看,在调试时我注意到intentService构造函数从未被调用过。

1 个答案:

答案 0 :(得分:1)

我的证词错了,应该是:

<service 
         android:enabled="true"  
         android:name="com.shale.services.SaleServiceForImages" 
/>