I want a helper class to evaluate javascript with WebView:
public class EvaluateHelper {
public static String evaluate(String st){
WebView w;
String result;
//something code to evaluate javascript using WebView;
return result;
}
}
But the creation of web view needs a context, I want this class self-contained and do not want to modify other activity class to provide a context, I tried some methods:
fulfil with null
WebView w=new WebView(null);
fulfil with new Activity
WebView w=new WebView(new Activity());
fulfil with context in new Application
WebView w=new WebView(new Application().getApplicationContext());
create custom child class from context, then provide my custom class for WebView:
class MyContext extends Context{ //some override method } WebView w=new WebView(new MyContext());
but they cause failed to run the app. Is there other way that create a WebView with my Context instead of app original Context? If not, is it possible to make this class self-contained?