从外部类调用活动方法
我真的对所有这些应用程序/活动上下文的东西感到困惑。我想从类中调用一些活动方法,例如我自己的 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); // ??
}
}
如何实现?是否有任何合理的模式可以帮助我避免内存泄漏?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定。
i'm not quite sure.