开发者

My main Activity launches a new Activity (WebView). It's just a page. But when I click the "Back" button...a white screen appears?

public class Profile extends Activity{
    WebView prof_webv;  
    private String selected_username;
    private static final String INDEX = "http://14.143.227.140";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    prof_webv = (WebView) findViewById(R.id.mainwebview);
    prof_webv.getSettings().setJavaScriptEnabled(true);
    prof_webv.getSettings().setSupportZoom(false);
    prof_webv.loadUrl(INDEX);

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) ) {
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
}

This is my new Activity for a WebView. When the user clicks back, I simply want to close this Activity and return to my previous one. Notice, I put "onKeyDown" 开发者_开发知识库-> Finish.

However, it's not working. Instead, I click "back", a blank white screen comes up.. (it doesn't even hit that onKeyDown Statement when I try to debug it)!

When I hit "back" the second time, then it will go back to my previous Activity.


I fixed it. You gotta do this:

private class ProfileWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView prof_webv, String url) {    
            prof_webv.loadUrl(url);
            return true;
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜