title: How can I access a WebView in my Activity from Application class without memory leak?
body: <p>I feel like the answer should be obvious but I can't find it.  How do I reference a WebView in my main activity from Application class?  Using a public static var to hold a reference to it in Activity class is causing a memory leak.  </p>
  
  <p>Current code (works, but causes memory leak).</p>
  
  <p>Activity</p>
  
  <pre><code>public class Core extends AppCompatActivity {
  
  public static WebView coreView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_core);
  
      WebView myWebView = (WebView) findViewById(R.id.webview);
      WebSettings webSettings = myWebView.getSettings();
      webSettings.setJavaScriptEnabled(true);
      webSettings.setDomStorageEnabled(true);
      webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      myWebView.setWebViewClient(new WebViewClient());
      myWebView.setPadding(0,80,0,0);
  
      coreView = myWebView;
  }
  }
  </code></pre>
  
  <p>Application</p>
  
  <pre><code>public class App extends Application {
  @Override
  public void onCreate() {
      super.onCreate();
  
      Core.coreView.loadUrl("http://www.google.com");
  
  }
  </code></pre>
  
  <p>EDIT:
  Full App class.</p>
  
  <pre><code>public class App extends Application {
  @Override
  public void onCreate() {
      super.onCreate();
  
      OneSignal.startInit(this)
              .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
              .setNotificationOpenedHandler(new MainNotificationOpenedHandler())
              .setNotificationReceivedHandler(new MainNotificationReceivedHandler())
              .unsubscribeWhenNotificationsAreDisabled(true)
              .init();
  
      OSPermissionSubscriptionState status = OneSignal.getPermissionSubscriptionState();
  }
  
  private class MainNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
      // This fires when a notification is opened by tapping on it.
      @Override
      public void notificationOpened(OSNotificationOpenResult result) {
          OSNotificationAction.ActionType actionType = result.action.type;
          JSONObject data = result.notification.payload.additionalData;
          String customKey;
  
          Core.coreView.loadUrl(result.notification.payload.launchURL);
      }
  }
  
  private class MainNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
      @Override
      public void notificationReceived(OSNotification notification) {
          JSONObject data = notification.payload.additionalData;
      }
  
  }
  </code></pre>
  
  <p>}</p>