没有从广播接收器调用新活动

时间:2012-11-29 21:10:13

标签: android dialog android-fragments broadcastreceiver

新的对话框frament类没有被调用y是这样的.. ??它在异常中烘烤消息以及吐司

public class AlarmReceiver extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {
   try {
     Bundle bundle = intent.getExtras();
     String message = bundle.getString("alarm_message");
     Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
     Intent newIntent = new Intent(context, FireMissilesDialogFragment.class);
    newIntent.putExtra("alarm_message", message);
     newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  //   Toast.makeText(context, "1"+message, Toast.LENGTH_SHORT).show();

     context.startActivity(newIntent);
   //  Toast.makeText(context, "2"+message, Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
     Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
     e.printStackTrace();

    }
 }

}

1 个答案:

答案 0 :(得分:0)

您无法通过意图启动片段 - 您需要开始一项活动