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".
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android Training in NYC: 1-2 May 2010: http://guruloft.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en