My query is taking < 3 milli sec to execute. But the problem is, I am creating a pojo class objects from the cursor I got from query execution. This object creation and setting values to fields is taking too much time more than 140 milli sec. Pojo class has around 36 fields. Any suggestion to solve this problem.?
Thanks
I know that the c.getColumnIndex()
method takes more time. The best method that I know to speed up the things is the following:
Cursor c = null;
try {
c = db.query(......);
if(c != null) {
int channelIdIndex = c.getColumnIndex(OptimizedMessage.CHANNEL_ID);
int clientIdIndex = c.getColumnIndex(OptimizedMessage.CLIENT_ID);
while (c.moveToNext()) {
OptimizedMessage newMessage = new OptimizedMessage();
newMessage.setChannelId(c.getLong(channelIdIndex));
newMessage.setClientId(c.getLong(clientIdIndex));
messages.add(newMessage);
}
}
} finally {
if (c != null) {
c.close();
}
}
You can see that the c.getColumnIndex()
method is used only once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With