I'm working on the structure for a database, in Android Studio. I am not at the stages of testing, yet, but understanding smaller details in how it works would allow me to write a better structure sooner rather than later. Unfortunately, there is one small element that am unsure of that has proved rather difficult to look for, online.
I create an SQLiteDatabase
, and use it to store values that I represent in a class called Task
. When I enter each Task
into the database, I also retrieve the Id to store into my local container newTask
, with newTask.SetId(mTaskDataSource.Create(newTask))
. I ultimately use the SQLiteDatabase
to store my tasks across sessions, and use a RecyclerView
to display the list in an activity. This means that I have to keep track of the elements position in both the SQLiteDatabase
and the RecyclerView
.
If I delete an element in the database, will the consecutive element Ids "cascade down", or will they stay at their original values? If an example is needed, consider that my database stores elements, and displays the Ids. If I start with {0, 1, 2, 3}
, and remove element 2
, will my database balance its Ids back to {0, 1, 2}
, or will I have {0, 1, 3}
?
As I am working off the assumption that it balances back ({0, 1, 2}
), I have realised that I potentially set myself up for a lot of extra/redundant work, if my assumptions are wrong. If it does not balance in this way, is there a reasonably cheap way to do so?
I am asking if ID numbers will rebalance themselves. This is not the same as asking what the ID number is actually for, nor is the duplicate question of any valid use to my question. I am asking specifically in regards to an SQLiteDatabase
, not a generic Adapter
.