title: How to use SQLite from Services in Android?
body: <p>It's sad how hard it is to find a simple line of code that does this "In my opinion". <br/></p>
  
  <p>Anyhow, the problem is I have a program with activities and services "I am new to services". <br/> I can access my SQLite DataBase from activities using</p>
  
  <p>TheDB class:</p>
  
  <pre><code>public TheDB(Context context) {
      this.context = context;
      OpenHelper openHelper = new OpenHelper(this.context);
      this.db = openHelper.getWritableDatabase();
  }
  </code></pre>
  
  <p>And then I can just call the methods, e.g. </p>
  
  <p>myActivity class:</p>
  
  <pre><code>private TheDB db;
  bla... bla... bla...
  this.db = new TheDB(this);
  db.insertSomething(id, name);
  </code></pre>
  
  <p>TheDB class (method called from myActivity):</p>
  
  <pre><code>public void insertSomething(String id, String name){
      db.execSQL("INSERT into " + farmsTable
  + " (id, name)"
  + " Values "
  + " (" + id + ", '" + name  + "')");
  }
  </code></pre>
  
  <p>ALL I want to be able to do is call TheDB's methods from my service like I do from myActivity.</p>
  
  <p>Do I make a new constructor? Do I change the way I instantiate it?</p>