Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The bolded font in the citation corresponds to this part in your code:</p> <pre><code>private DatabaseManager open() throws SQLException { dbHelper = new DatabaseHelper(context); db = dbHelper.getWritableDatabase(); </code></pre> <p>from: <a href="http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html" rel="noreferrer">http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html</a></p> <blockquote> <p>Approach #1: Use an Abstract Factory to Instantiate the SQLiteOpenHelper</p> <p>Declare your database helper as a static instance variable and use the Abstract Factory pattern to guarantee the singleton property. The sample code below should give you a good idea on how to go about designing the DatabaseHelper class correctly.</p> <p>The static factory getInstance method ensures that only one DatabaseHelper will ever exist at any given time. If the mInstance object has not been initialized, one will be created. If one has already been created then it will simply be returned. <br/><br/> <strong>You should not initialize your helper object using with <em><code>new DatabaseHelper(context)</code></em>. <br/> Instead, always use <em><code>DatabaseHelper.getInstance(context)</code></em>, as it guarantees that only one database helper will exist across the entire application's lifecycle.</strong></p> </blockquote> <pre><code>public static class DatabaseHelper extends SQLiteOpenHelper { private static DatabaseHelper mInstance = null; private static final String DATABASE_NAME = "database_name"; private static final String DATABASE_TABLE = "table_name"; private static final int DATABASE_VERSION = 1; public static DatabaseHelper getInstance(Context ctx) { // Use the application context, which will ensure that you // don't accidentally leak an Activity's context. // See this article for more information: http://bit.ly/6LRzfx if (mInstance == null) { mInstance = new DatabaseHelper(ctx.getApplicationContext()); } return mInstance; } /** * Constructor should be private to prevent direct instantiation. * make call to static factory method "getInstance()" instead. */ private DatabaseHelper(Context ctx) { super(ctx, DATABASE_NAME, null, DATABASE_VERSION); } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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