We already proved that what you did here worked yesterday.
I don't want to setContentView to the webview initially. I want
to be able to paint up a screen and switch to the webview later,
via user control (ie, a button/menuitem).
1) I don't know what you mean by "never implement a constructor
in an Activity".
2) it doesn't matter where the constructor for the WebView is
called. It's the second setContentView call being called from the
menu/button click method that's causing the problem seemingly.
3) the return value of the onMenu doesn't affect the outcome here
4) Is a rather facile dodge, IMO. I call it from the button/menu listener
so that I can act on a user request which doesn't seem like it's asking
for a whole lot. Dismiss it as "not serious" if you like, but this
seems like
it's forcing me to code this as an Intent which would give a seriously
horrible user experience.
Mike
On 03/17/2010 02:34 PM, Mark Murphy wrote:
mike wrote:
Ok, here is a complete app that exhibits the problem. The key that is
necessary is to
do a setContentView from the menuItem/onClick/onLongClick. It doesn't
help if you
postpone it either, eg using handler.postDelayed() and such.
This is a rather serious bug for anything that uses a WebView.
1. Never implement a constructor in an Activity.
2. If you choose to violate rule #1, chain to the superclass.
3. If you handle an option menu item, return true.
4. If calling setContentView() with a WebView parameter in a context
menu handler causes problems with embedded<input> tags, then don't call
setContentView() with a WebView parameter in a context menu handler.
So, for example, this works just fine:
package com.commonsware.android.scrap;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
public class ScrapProject extends Activity {
WebView w=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
w=new WebView(this);
setContentView(w);
}
public boolean onCreateOptionsMenu (Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, 0, Menu.NONE, "Test");
return result;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 0:
w.loadDataWithBaseURL("http://this/is/so/fake",
"<html><body>fooz<input></body></html>",
"text/html",
"utf8", null);
return(true);
}
//return super.onOptionsItemSelected(item);
return false;
}
}
There's no question that you have uncovered something odd, but I would
not characterize it as a "serious bug".
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en