为什么我的receiver在执行完onReceive后程序就崩溃呢?我在activity的onCreate里面 注册了一个广播,然后启动一个service
这个service是继承自IntentService
在onHandleIntent这个函数里面什么也没干就调用sendBroadcast发广播
然后receiver的onReceive就调用了,这个函数什么也没干就调用System.out.println("msg received")
执行完程序就崩溃了。。
找了一天原因了,还是不知道为什么
求解

解决方案 »

  1.   

    代码就下面两个文件
    StartUpActivity.java
    public class StartUpActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.main);
            RSSDownloadServiceReceiver receiver = new RSSDownloadServiceReceiver(this);
            IntentFilter filter = new IntentFilter("com.xxxx.activity.MsgReceived");
            registerReceiver(receiver, filter);
            
            Intent intent = new Intent(this, RSSDownLoadService.class);
            startService(intent);
        }
        private class RSSDownloadServiceReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
         System.out.println("msg received");
         }
        }
    }
    RSSDownLoadService.java
    public class RSSDownLoadService extends IntentService { public RSSDownLoadService()
    {
    super("RSSDownLoadServiceThread");
    }

    @Override
    protected void onHandleIntent(Intent arg0) 
    {         Intent it = new Intent("com.xxxx.activity.MsgReceived");
    sendBroadcast(it);
    }}
      

  2.   

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.xxxx.activity"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-permission android:name="android.permission.INTERNET" />     <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".StartUpActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <receiver android:name=".RSSDownloadServiceReceiver">
             <intent-filter>
             <action android:name="com.xxxx.activity.MsgReceived" />
             </intent-filter>
            </receiver> <service android:enabled="true" android:name="com.xxxx.service.RSSDownLoadService" />
        </application>
    </manifest>
      

  3.   

    08-30 15:59:11.201: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
    08-30 15:59:12.419: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{40853010 com.xxxx.activity/.StartUpActivity}