1

我正在创建我的第一个intent service,我已按照教程进行操作,但由于某种原因,我的意图服务从未启动。我正在尝试调用intentServicefrom 片段。这是我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一些函数开始调用,这里是代码:AsyncTaskonPostExecute

        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);

图像销售服务

    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构造函数从未被调用过。

4

1 回答 1

1

我的清单错了,应该是:

<service 
         android:enabled="true"  
         android:name="com.shale.services.SaleServiceForImages" 
/>
于 2013-06-08T07:56:39.013 回答