我需要显示一个网页几秒钟,然后开始另一个活动。我正在做的是 onResume() 方法,我调用 Thread.sleep() 然后启动新活动,但是当我执行它时,它没有显示网页。它显示一个黑屏,并执行下一个活动。我可能做错了什么?这是我的代码:
public class ShowPortalActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "http://someurl.com";
WebView webview = (WebView) findViewById(R.id.webView);
// next line explained below
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(url);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
try {
newActivity();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void newActivity() throws InterruptedException {
Thread.sleep(3000);
Intent intent = new Intent(ShowPortalActivity.this, Inicio.class);
startActivity(intent);
}
}