我有一个启动屏幕的活动,它在布局中只有一个图像。我想在 UI 线程中显示初始屏幕时在后台进行一些 Http 调用。但是当我执行 AsyncTask 时,布局中的图像不会显示。我只得到一个空白屏幕,让我相信布局本身没有加载。下面是活动代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
String authReqResponse;
Toast errorDisplayToast = new Toast(this);
AuthorizationRequest authReq = new AuthorizationRequest();
authReq.execute(new Void[] {});
try {
authReqResponse = authReq.get();
if(authReqResponse.equalsIgnoreCase(GeneralConstants.AUTH_FAILED_ERROR)) {
errorDisplayToast.makeText(SplashScreen.this, R.string.request_auth_failed_error_message, Toast.LENGTH_LONG);
errorDisplayToast.show();
} else if(authReqResponse.equalsIgnoreCase(null)) {
errorDisplayToast.makeText(SplashScreen.this, R.string.networkErrorMessage, Toast.LENGTH_LONG);
errorDisplayToast.show();
} else {
GeneralConstants.REQ_TOKEN = authReqResponse;
Intent startARIntent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(startARIntent);
finish();
}
} catch(Exception e) {
e.printStackTrace();
}
}