views:

91

answers:

1

Hello, I am new to Android and java development. I create a WebView object in the OnCreate function. Now I need to be able to pass this same object to other functions in the code, such as the onOptionsItemSelected function. I currently have it where I just create a new WebView object in each function where I need it, but this slows down the code since it has to recreate it and such.

+1  A: 

Something as simple as this?

public class MyActivity extends Activity {

    WebView wv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        wv = new WebView(this);
        setContentView(wv);

    @Override
    public boolean onOptionsItemSelected(MenuItem  item){
        wv.doSomething();
    }
RichieHindle