1
我有該廣播接收機註冊Android:爲什麼BroadcastReceiver崩潰?
public class NotifyAlarmBroadcast extends BroadcastReceiver{
public Context context;
public static final String NOTI = "android.intent.action.MAIN";
// actually i want NOTI = "com.sumit.timekeeper.NotifyAlarm"
// this too is not working
// help me here please
@Override
public void onReceive(Context _context, Intent intent) {
context = _context;
Uri data = intent.getData();
String reason = intent.getStringExtra("alarm_reason");
Intent intentalarm = new Intent(NOTI, data);
intentalarm.putExtra("reason", reason);
context.startActivity(intentalarm);
}
}
和清單
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TimeKeeperStartActivity"
android:screenOrientation="portrait" 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=".NotifyAlarm"
android:screenOrientation="portrait" android:theme="@android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.sumit.timekeeper.NotifyAlarm">
</action>
</intent-filter>
</activity>
<receiver android:name=".NotifyAlarmBroadcast">
<intent-filter>
<action android:name="com.sumit.timekeeper.NotifyAlarmBroadcast" />
</intent-filter>
</receiver>
</application>
但當線到達context.startActivity(intentalarm); 應用程序崩潰
可能是我們將第一個參數傳遞給Intent的地方,我不清楚 請幫助我。
您可能有更多關於LogCat崩潰的信息(DDMS - > LogCat標籤) – ccheneson 2010-02-19 09:40:32
嗨ccheneson,感謝您的迴應。 LogCat在context.startActivity(intentalarm)處顯示崩潰; 。此外,我也嘗試了AlerDialog,當命中alertDialogObj.show()崩潰...正常意圖與NotifyAlarm.class param也崩潰時,點擊context.startActivity(intentObj); ?我處於非常天真的階段,我甚至無法理解操作系統級別發生了什麼。 – 2010-02-19 09:46:01
工作正常的唯一的東西是Toast,它在到達toastObj.show()時不會崩潰() – 2010-02-19 09:47:21