我的游戏需要很长时间才能从后台加载。在加载期间,屏幕为黑色(大约5到7秒,因此用户可能会认为它崩溃了)。
我决定在进入前景时显示敬酒。
protected void onResume() {
System.out.println("onResume method called");
Context context = getBaseContext();
// Context context = getApplicationContext();
CharSequence text = "i appreciate your patience";
Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
toast.show();
super.onResume();
wl.acquire();
if (accelerometerEnabled) {
accelerometer.enable();
}
}
但是烤面包仅在恢复完成后才会显示(这使它无用)
我已经尝试过getApplicationContext,getBaseContext以及Activity本身。
因此可以在没有我的应用程序上下文的情况下直接在窗口上添加吐司吗? (也许在系统级别的上下文中)
最佳答案
我认为这与您的游戏从后台返回时在UI线程上的加载有关
尝试将所有非UI线程相关的逻辑移到AsyncTask中。
这应该使您的吐司消息在游戏加载时可见。