I am new to Android and java dev开发者_高级运维elopment. 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.
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();
    }
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论