Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've used this approach:</p> <p>Create a class responsible for managing the db, let's call it <code>DBUtil</code>. This class will extend <code>android.database.sqlite.SQLiteOpenHelper</code>. You can pass a reference to the application context to the constructor of this class. This class will contain methods for creating the db, adding, removing and retrieving items.</p> <p>Create another class, let's call it <code>AppCore</code>, create a static instance of the <code>DBUtil</code> and a static <code>init()</code> method that accepts an <code>ApplicationContext</code> object</p> <pre><code>public class AppCore { public static var dbUtil:DBUtil; public static void init( ApplicationContext context ) { dbUtil = new DBUtil( context ); } } </code></pre> <p>Then in the onCreate() method of our your application's main <code>Activity</code>, initialize the <code>AppCore</code> class.</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { AppCore.init( getApplicationContext() ); } </code></pre> <p>So, it's not really a Singleton. Instead, the DBUtil instance is maintained as a static property, yet still accessible throughout your application, such as this:</p> <pre><code>AppCore.dbUtil.createNewRecord( params ); </code></pre> <p>Also, I found this tutorial to be very helpful when getting started with this topic: <a href="http://developer.android.com/guide/tutorials/notepad/index.html" rel="nofollow noreferrer">http://developer.android.com/guide/tutorials/notepad/index.html</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload