I'm trying to declare a global variable but without success. I was following this tutorial but this doesn't work if I want to transfer a variable from fragment to MainActivity.
First I added this code to my fragment class:
public class WebViewFragment extends Fragment{
private WebView myState;
public WebView getState(){
return myState;
}
public void setState(){
myState = webView;
}
}
And then I added this to my MainActivity
but it doesn't work:
WebViewFragment appState = ((WebViewFragment)getApplicationContext());
WebView state = appState.getState();
I get this error: Cannot cast from Context to WebViewFragment