android - 警报对话框 + 意图

android - Alert Dialog + intent

public void screen2 (View view) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("screen2");
    builder.setMessage("go to screen2?");

    builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(this,Screen2Activity.class);
            startActivity(intent);
        }
    }
}

我想从 AlertDialog 启动 activity,但我在 Intent intent = new Intent(this,Tela2Activity.class);

上发现错误

screen2 链接到按钮的 'onclick'

更改这部分代码:

Intent intent = new Intent(this,Screen2Activity.class);
startActivity(intent);

为此:

Intent intent = new Intent(FirstActivity.this,Screen2Activity.class);
startActivity(intent);

完整代码:

public void screen2 (View view) {

final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("screen2");
builder.setMessage("go to screen2?");

builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        Intent intent = new Intent(FirstActivity.this,Screen2Activity.class);
        startActivity(intent);

}