无法在onNewIntent()中显示警报

时间:2013-05-14 11:37:11

标签: android android-alertdialog android-pendingintent

我在onNewIntent(Intent intent)功能中显示警告时遇到问题。正在检索Pending Intent extra并按预期记录其值,但不显示警报。

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Bundle extras = getIntent().getExtras();
    if(extras !=null) {
        String value = extras.getString("message");
        Log.v("alert", value);  // <--- this line works fine.


        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("title");
        alertDialog.setMessage(value);
        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {


            }
        });

        alertDialog.show();
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

AlertDialog alertDialog = new AlertDialog.Builder(YourActivity.this).create();