I am really confused with all this application/activity context stuff. I want to call some of activity methods from classes, such as my own WebChromeClient
or ConnectionChangeReceiver
(detecting network connection changes).
Example code:
public class MyWebChromeClient extends WebChromeClient {
MyWebView webview;
MyApp app;
// own constructor to store info about webview which is used in the current
//webchrome client
public MyWebChromeClient(Context context, MyWebView wv)
{
this.webview = wv; // store information about current webview (leaks?)
this.app = context.getApplicationContext(); // store app context
}
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
app.getActivityWhichIsUsingThisWebView().logFromWebView(webview, message); // ??
}
}
How to achieve that? Is there any sensible pattern which could help me avoiding memory leaks?