I wanted to start a service from a Broadcast reciever which takes “android.intent.action.BOOT_COMPLETED”. When I write click on the Application in eclipse and launch it It runs well. But when I launch it from emulator on which it has already been installed, the application crashes. The following are the source codes.
AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.newsreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="15" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:logo="@drawable/logo"
android:theme="@style/NewsReaderStyle" >
<receiver
android:name=".StartupIntentReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service android:name=".LoadFeedsService" ></service>
<activity
android:name=".NewsReaderActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ArticleActivity"
android:theme="@style/NewsReaderStyle_NoActionBar" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>*
and my BroadCast reciever is
*package com.example.android.newsreader;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class StartupIntentReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Log.i("reciever", "recieved intent"+ intent);
Intent serviceIntent = new Intent(context, LoadFeedsService.class);
context.startService(serviceIntent);
}
}*
Thanks in Advance.
Modify your receiver code as below and try.
If the above modification is not working modify service also as below and try.
In java code of receiver modify as below.
I hope it may help you.