0

我真的对所有这些应用程序/活动上下文的东西感到困惑。我想从类中调用一些活动方法,例如我自己的WebChromeClientConnectionChangeReceiver(检测网络连接更改)。

示例代码:

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); // ??
      }

}

如何做到这一点?是否有任何明智的模式可以帮助我避免内存泄漏?

4

1 回答 1

1

我不太确定。

Activity activity;

public MyWebChromeClient(Context context, MyWebView wv,Activity activity)
{
    this.webview = wv; // store information about current webview (leaks?)
    this.app = context.getApplicationContext(); // store app context 
    this.activity = activity;
}
于 2011-12-28T10:32:03.840 回答