Cursor c = database.rawQuery("SELECT last_insert_rowid()", null); c.moveToFirst(); int id = c.getInt(0); id += 1;
I am also a beginner, so I canβt explain very well. The above will contain the last insert identifier from the same session. It will not work if a new session is started, i.e. You insert something and close the connection and open it again, since it will return 0, so you need to remember this, since your TextView will always show 1. How did you read a lot of questions about it, not knowing how to implement it. The above code is how I managed to use it without getting exceptions due to errors.
source share