如何在同一应用不同的活动中使用XWalkView
和WebView
?
在Android中,KITKAT webview
不支持上传。 Crosswalk修好了它。但现在我在两个不同的活动中使用了两个不同的webview
(XWalkView
和WebView
)。
if(sdkVersion == Build.VERSION_CODES.KITKAT){
Intent myIntent = new Intent(StartActivity.this, MainActivity.class); // this use XWalkView
StartActivity.this.startActivity(myIntent);
} else {
Intent myIntent = new Intent(StartActivity.this, Main2Activity.class); // this use Webview
StartActivity.this.startActivity(myIntent);
}
并收到此错误
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.foo/com.example.foo.Main2Activity}:
java.lang.ClassCastException:
org.xwalk.core.XWalkView cannot be cast to android.webkit.WebView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassCastException: org.xwalk.core.XWalkView cannot be cast to android.webkit.WebView
az.azgram.azgram.Main2Activity.onCreate(Main2Activity.java:74)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)