【发布时间】:2016-07-14 18:02:58
【问题描述】:
我正在尝试在 ProgressUpdate() 方法上显示 Toast。在 Android 4,5 上运行良好,但在 android 6 上不显示 toast 并且没有抛出异常。
这是我的方法:
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
Toast.makeText(getApplicationContext(), values[0], Toast.LENGTH_SHORT).show();
}
如果我用 getBaseContext() 替换 getApplicationContext(),Toast 会按预期工作。
如果我使用 MainActivity.this 作为上下文,它不起作用
使用 getBaseContext() 是否正确? 为什么在 android 4,5 而不是 6 上使用 getApplicationContext()?
【问题讨论】: