我的
android webview函数onPageFinished被调用两次.我不知道为什么,但它在
Android 2.2上运行良好,但当我升级到4时它不起作用.代码如下
码
@Override
public void onPageFinished(WebView view, String url) {
if (url.startsWith(MobileConstants.PUSHPIN_CALLBACK_URL)) {
if (url.indexOf("code=")!=-1) {
String code = url.substring(url.indexOf("code=")+5);
Log.i ("code", code);
if (code != null && !code.equals("") ){
view.setVisibility(View.GONE);
Token accessToken = service.getAccessToken(null, new Verifier(code));
Log.i("access_token",accessToken.getToken());
SharedPreferences settings = getSharedPreferences("access_token" , 0);
SharedPreferences.Editor editor = settings.edit();
if(accessToken.getToken() != null)
editor.putString("access_token", accessToken.getToken() );
Intent map3 = new Intent(OAuthAccessTokenActivity.this, Dashboard.class);
map3.putExtra("access_token", accessToken.getToken());
startActivity(map3);
}
} else if (url.indexOf("error=")!=-1) {
view.setVisibility(View.INVISIBLE);
}
}
System.out.println("onPageFinished : " + url);
}
日志
07-22 14:29:50.523: E/AndroidRuntime(1186): FATAL EXCEPTION: main
07-22 14:29:50.523: E/AndroidRuntime(1186): java.lang.NullPointerException
07-22 14:29:50.523: E/AndroidRuntime(1186): at com.facebook.android.OAuthAccessTokenActivity$1.onPageFinished(OAuthAccessTokenActivity.java:83)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:327)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.os.Looper.loop(Looper.java:137)
07-22 14:29:50.523: E/AndroidRuntime(1186): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-22 14:29:50.523: E/AndroidRuntime(1186): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 14:29:50.523: E/AndroidRuntime(1186): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 14:29:50.523: E/AndroidRuntime(1186): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-22 14:29:50.523: E/AndroidRuntime(1186): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-22 14:29:50.523: E/AndroidRuntime(1186): at dalvik.system.NativeStart.main(Native Method)