Marcos Vasconcelos Marcos Vasconcelos - 6 months ago 32
Android Question

Get generated id after insert

I'm using the SQLite with Android, and I want to know the best way to get the generated id of the row I inserted.

A solution I think is make a search after include, but it's doesn't look the best way.

Answer

The insert method returns the id of row just inserted or -1 if there was an error during insertion.

long id = db.insert(...);

where db is SQLiteDatabase.