我想從一個需要「android.intent.action.BOOT_COMPLETED」的廣播接收器啓動服務。當我在eclipse上點擊應用程序並啓動時,它運行良好。但是當我從它已經安裝的模擬器啓動它時,應用程序崩潰。以下是源代碼。當我使用廣播接收器時,應用程序崩潰
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>*
和我廣播reciever事先
*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);
}
}*
感謝。
崩潰? Logcat輸出中的崩潰報告是什麼? – 2012-02-10 05:27:35
其實..有更多的問題在那裏。我的後臺服務是從互聯網獲取數據,可能互聯網連接直到收到廣播時纔可用... – Ahmad 2012-02-10 07:34:29