我正在使用这个提示框来弹出消息,告诉用户没有可用的活动互联网连接。
我希望当用户点击“确定”时能够返回到MainActivity,但我似乎无法实现这一点。
package com.xx.xx.xxhelper;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
public class AlertDialogManager {
public void showAlertDialog(Context context, String title, String message,
Boolean status) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
if(status != null)
// Setting alert dialog icon
alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
// Showing Alert Message
alertDialog.show();
}
}
我已经添加了。
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(AlertDialogManager.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent);
}
});
但是我收到了以下错误:
- 构造函数Intent(AlertDialogManager, Class)未定义
- 方法startActivity(Intent)未定义于new DialogInterface.OnClickListener(){}
有什么线索吗?