AndroidPenguin AndroidPenguin - 1 year ago 107
Android Question

Table storage for strings and booleans

I've implemented in-app-billing v3 and I'd like a way to keep some sort of table which contains 3 columns

(String) Name of product, (String) sku, (boolean) true/false

What is the best way to do this? The best way would (in my opinion) allow me to keep a static easily readable list of values where the first two were strings, the third a boolean. At the start all the values for the boolean column were false, but as I query purchases I am able to easily reset the value.

Just to add,

I'm against SQLite databases for the reason that they're just too easy to hack. I'd rather create it in code and thus I'm debating between an ArrayList within an arraylist or matrices or something like the following:

private static class CatalogEntry {
public String sku;
public String name;

public CatalogEntry(String sku, String name) {
this.sku = sku; = name;

private static final CatalogEntry[] CATALOG = new CatalogEntry[] {

new CatalogEntry("android.test.purchased", "Item1"),
new CatalogEntry("android.test.canceled", "Item2"),
new CatalogEntry("android.test.refunded", "Item3"),
new CatalogEntry("android.test.item_unavailable", "Item4")


Is there a way to reset values in the CATALOG array if I add a third column, otherwise I'm considering using both that and standard arraylists.

Answer Source

Use sqlite with FOUR columns:

  • sku
  • name
  • purchaseDate (or null if not purchased)
  • md5Hash

When a purchase is made, you just concatenate the sku, name, purchaseDate, device-id, and a PSK, make an md5Hash and store it along with the other data in the row. When you check the contents of the table, you compare the md5 stored against the data, and you can verify whether the purchase was valid, or the table has been tampered with. You can even let the user back up the purchase table to sdcard (or use Android backup).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download