0
我真的很困惑所有这些应用程序/活动上下文的东西。我想从类中调用一些活动方法,例如我自己的WebChromeClient
或ConnectionChangeReceiver
(检测网络连接更改)。从外部类调用活动方法
示例代码:
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); // ??
}
}
如何实现这一目标?有没有什么明智的模式可以帮助我避免内存泄漏?
是不是导致内存泄漏? (http://developer.android.com/resources/articles/avoiding-memory-leaks.html)“尝试使用上下文应用程序而不是上下文活动” – Piotr 2011-12-28 10:35:38