title: Android Service continues to disconnect when closing the application
body: <p>I had previously managed to get my service to continue running. But today after I went back to the application to keep working with the app I noticed that the service gets disconnected after the app is closed which was not happening before.</p>
  
  <p>I start the service in my main activity like this:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // setContentView(R.layout.activity_main);
          if(savedInstanceState == null) {
              setContentView(R.layout.activity_main);
              Intent i  = new Intent(MainActivity.this, SystemWebService.class);
              SystemWebService.setMain(this);
              MainActivity.this.startService(i);
  
          }
  </code></pre>
  
  <p>The code in the SystemWebService class looks like this:</p>
  
  <pre><code> public class SystemWebService extends Service {
  
          private static WebView webdemo;
          private static MainActivity ma;
          //Context dex;
  
          @Nullable
          @Override
          public IBinder onBind(Intent intent) {
              return null;
          }
  
          @Override
          public  int onStartCommand(Intent intent, int flags, int startId){
              // let the service continue until stopped
              Toast.makeText(this, "Service has started", Toast.LENGTH_SHORT).show();
              return START_STICKY;
          }
  
          @Override
          public void onDestroy(){
              super.onDestroy();
              Toast.makeText(this, "Service has been destroyed", Toast.LENGTH_SHORT).show();
          }
  
          @Override
          public void onCreate() {
              super.onCreate();
  
          }
  
          public static void setMain(MainActivity a) {
              ma = a;
              SystemWebService sws = new SystemWebService();
              sws.setView();
          }
  }
  </code></pre>
  
  <p>This is the code that sets the webview</p>
  
  <pre><code>public  void setView() {
          webdemo = (WebView) ma.findViewById(R.id.webdemo);
          webdemo.addJavascriptInterface(new SystemWebService.WebAppInterface(this), "Android");
          webdemo.setWebViewClient(new WebViewClient(){
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest url){
                  return false;
              }
          });
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              webdemo.getSettings().setJavaScriptEnabled(true);
              webdemo.getSettings().setDomStorageEnabled(true);
              webdemo.getSettings().setAllowFileAccessFromFileURLs(true);
              webdemo.getSettings().setAllowUniversalAccessFromFileURLs(true);
          }
  
          webdemo.loadUrl("file:///android_asset/_wv.html");
      }
  </code></pre>
  
  <p>The webview establishes a connection to our server and I would normally see data display on the logs. Before I would continue to see the flux of data passing even after the application was closed but as of right not I am not seeing anything, only the message "Application terminated".</p>
  
  <p>I can't seem to understand what is happening.</p>