2011-12-28 121 views
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); // ?? 
     } 

} 

如何實現這一目標?有沒有什麼明智的模式可以幫助我避免內存泄漏?

回答

1

我不太確定。

​​
+0

是不是導致內存泄漏? (http://developer.android.com/resources/articles/avoiding-memory-leaks.html)「嘗試使用上下文應用程序而不是上下文活動」 – Piotr 2011-12-28 10:35:38