I'm developing an Android application that has 2 Activities. In one activity I have a webview (parent) that creates the child webview by using the WebChromeClient's onCreateWindow. On the web code side, I store the reference of window.open() that causes onCreateWindow to create the child webview and send messages to it.
Activity 1:
mWebViewParent.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onCreateWindow(WebView webview, boolean isDialog, boolean isUserGesture, Message message) {
WebView.WebviewTransport transport = (WebView.WebviewTransport) message.obj;
childWebView = new WebView(mContext);
transport.setWebView(childWebView);
message.sendToTarget();
}
});
I get messages from the web code to start the second activity and finish it. Since I only store one reference of the window from the web code's window.open()
, I don't destroy the webview, but just finish the activity;
Activity 1:
private BroadcastReceiver secondActivityStarted = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Activity activity = ActivityStack.getActivity();
activity.setContentView(childWebView);
}
}
@JavascriptInterface
public void startActivity() {
IntentFilter filter = new IntentFilter("secondActivityStarted")
LocalBroadcastManager.getInstance(mContext).registerReceiver(secondActivityStarted, filter);
Intent intent = new Intent(mContext, SecondActivity.class);
mContext.startSecondActivity(intent);
}
@JavascriptInterface
public void finishActivity() {
Activity activity = ActivityStack.getActivity();
activity.finish();
ActivityStack.setActivity(null);
LocalBroadcastManager.getInstance(mContext).unregisterReceiver(secondActivityStarted);
}
Activity 2:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityStack.setActivity(this);
Intent actionIntent = new Intent("secondActivityStarted");
LocalBroadcastManager.getInstance(this).sendBroadcast(actionIntent);
}
The very first time, the child webview in the second Activity doesn't have any issues with the keyboard, but once I finish the activity and launch it again, the keyboard take a long time to show up, and what I type on the keyboard doesn't show up on the web's text fields.
What I have tried:
Setting and clearing the focus of the child webview
The link from window.open() gets lost using this: Saving the state of the child webview and message parameter from onCreateWindow(), destroying the child webview, creating the webview again, setting the state, and setting the new target for the new child webview.
Closing the keyboard in finish() of the SecondActivity.
Combinations of 1/2/3