【问题标题】:Calling activity methods from outside classes从外部类调用活动方法
【发布时间】:2011-12-28 09:53:56
【问题描述】:

我真的对所有这些应用程序/活动上下文的东西感到困惑。我想从类中调用一些活动方法,比如我自己的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); // ??
      }

}

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

【问题讨论】:

    标签: android android-activity android-context webchromeclient


    【解决方案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;
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 1970-01-01
    • 2014-06-28
    • 2023-03-23
    相关资源
    最近更新 更多