0

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();
    }
}
4

1 回答 1

0

试试这个:

AlertDialog alertDialog = new AlertDialog.Builder(YourActivity.this).create();
于 2013-05-14T11:48:05.087 回答