2013-06-08 2 views
1

Я создаю свой первый 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 так и не был вызван.

+0

вы фактически получаете в код, который запускает IntentService? – Ran

+0

где вы начали службу? –

+0

Да, отладчик попадает туда ('getActivity(). StartService (msgIntent);'), вызываемый из некоторого 'AsyncTask' из' 'onPostExecute''. – vlio20

ответ

2

я был неправ в своем манифесте, должно быть:

<service 
     android:enabled="true" 
     android:name="com.shale.services.SaleServiceForImages" 
/> 
Смежные вопросы