Assuming:
Your table is
create table example_table (
ts timestamp,
uid number(19),
some_other_field varchar(64)
);
And you don't want to care about running some query manually.
Use database triggers:
create trigger
if not exists -- I don't actually know if you DB will support this line.
-- Might want to remove it if it's not.
example_table_limiter
on example_table
after insert
begin
delete
from example_table
where ts in (
select ts
from example_table
order by ts
limit -1 -- we don't want to limit how many rows we want to delete
offset 25 -- but we want to offset query result so it leaves 25 rows in table
);
end;
"Offset without limit" syntax is inspired by this answer.
To enable your trigger in java:
Simple Android, where you can override SQLiteOpenHelper
:
public class DataBaseSchemaHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(<trigger string from above>);
}
}
Android Room version:
public class MyDatabase extends RoomDatabase {
@Override
public void init(DatabaseConfiguration _config) {
super.init(_config);
getOpenHelper().getWritableDatabase().execSQL(<trigger string from above>);
}
}