麻烦显示webview

时间:2012-08-08 04:22:44

标签: java android

我需要显示几秒钟的网页,然后开始另一项活动。 我正在做的是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);

}

}

2 个答案:

答案 0 :(得分:0)

@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);
            new Thread(new Runnable() {
                @Override
                public void run() {
                                  try {
                                        newActivity();
                                  } catch (InterruptedException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }

                        }
            }).start();    

}

void newActivity() throws InterruptedException {
    Thread.sleep(3000);
    Intent intent = new Intent(ShowPortalActivity.this, Inicio.class);
    startActivity(intent);
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();   
}

删除Resume代码并在create方法上替换此代码并立即尝试.... newActivity函数与旧代码相同....

答案 1 :(得分:0)

在您的Android清单文件中,是否提供了互联网许可。

如果没有添加以下代码。

<manifest xlmns:android...>
 ...
 <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>