Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>cr.delete(earthquakeProvider.CONTENT_URI, null, null); </code></pre> <p>This is your problem. First, some context:</p> <p>Content URIs: (<a href="http://developer.android.com/guide/topics/providers/content-providers.html#urisum" rel="noreferrer">source</a>)</p> <pre><code>content://authority/path/## </code></pre> <p>The number at the end is optional. If present, the URI references a specific row in the database where row._id=(the number). If absent, it references the table as a whole.</p> <p>the delete() call accepts a URI, a where clause, and a set of strings which get substituted in. Example: Say you have a database of people.</p> <pre><code>cr.delete( Person.CONTENT_URI, "sex=? AND eyecolor=?", new String[]{"male", "blue"}); </code></pre> <p>Will search the entire person table, and delete anyone whose sex is male and whose eye color is blue.</p> <p>If the where clause and where values are null, then the delete() call will match <em>every row in the table</em>. This causes the behavior you see.</p> <p>There are two methods to specify the row you want:</p> <p>First option, you could append the number to the URI: </p> <pre><code>cr.delete( EarthquakeProvider.CONTENT_URI.buildUpon().appendPath(String.valueOf(_id)).build(), null, null); </code></pre> <p>This restricts the URI to a specific row, and the path will be through your <code>case QUAKE_ID:</code> statement and so will only delete one row no matter what.</p> <p>Second option, you could use a where clause:</p> <pre><code>cr.delete(EarthquakeProvider.CONTENT_URI, "_id=?", String.valueOf(_id))); </code></pre> <p>Either way, you will restrict the delete to a single row, as you need it to. The latter makes for prettier code, but the former is more efficient, due to the way the ContentProvider and ContentObservers work.</p> <p>As a last note: In your ContentProvider you need to add a call to ContentResolver.notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork). This helps notify cursors to re-fetch the database query and helps out a lot with automation.</p>
    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