Reputation: 9295
I am creating my first intent service
, I have followed this tutorial but for some reason my intent service never starts. I am trying to call the intentService
from fragment. Here is my onCreate
code of the fragment:
@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;
}
Now the starting of the intentService
called from some AsyncTask
from it's onPostExecute
function, here is the code:
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);
}
}
Manifest
<?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>
No idea where to start looking, while debugging I notice that the intentService
constructor never been called.
Upvotes: 1
Views: 1766
Reputation: 9295
I was wrong at my manifest, should be:
<service
android:enabled="true"
android:name="com.shale.services.SaleServiceForImages"
/>
Upvotes: 1