Open yaopin002 opened 6 years ago
lz好,为什么在onSuccess回调里new 一个AlertDialog.Builder来创建对话框时,app就会奔溃呢?log也没有什么提示。代码如下: OkGo.get(ConstantValue.UPDATE_CHECK_URL) .tag(this) .params("Platform_type", 1) .params("OS", "Android7.0") .execute(new StringCallback() { @Override public void onSuccess(Response response) { //创建对话框 AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()); builder.setTitle("版本升级"). setIcon(R.mipmap.ic_launcher). setMessage("发现新版本!请及时更新"). setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ToastUtil.showToast(getApplicationContext(), "开始下载。。。。"); } }).setNegativeButton("取消", null); AlertDialog alertDialog = builder.create(); alertDialog.show();
不能用getApplicationContext(),换成当前activity或fragment的context
lz好,为什么在onSuccess回调里new 一个AlertDialog.Builder来创建对话框时,app就会奔溃呢?log也没有什么提示。代码如下: OkGo.get(ConstantValue.UPDATE_CHECK_URL)
.tag(this)
.params("Platform_type", 1)
.params("OS", "Android7.0")
.execute(new StringCallback() {
@Override
public void onSuccess(Response response) {
//创建对话框
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("版本升级").
setIcon(R.mipmap.ic_launcher).
setMessage("发现新版本!请及时更新").
setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ToastUtil.showToast(getApplicationContext(), "开始下载。。。。");
}
}).setNegativeButton("取消", null);
AlertDialog alertDialog = builder.create();
alertDialog.show();