我已注册此广播接收器
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的地方,我不清楚 请帮帮我。
答案 0 :(得分:2)
尝试在意图中添加FLAG_ACTIVITY_NEW_TASK标记。
intentalarm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);