To use SQLite efficiently with Service when receiving Android GCM notifications

Asked 2 years ago, Updated 2 years ago, 46 views

Defines the action of the receiver to start a service and notify the status bar when it receives a notification.
However, SQLite is used within the service to determine if the status bar is actually notified.

Currently, I have SQLite as static in the service. If onStartCommand is null, I will instantiate the database.
Also, it is closed every time on Destroy.

However, I think onDestroy will be called every time the service is terminated. I think I load the database every time I process 1 notification.

The database records are optimized every time the application is started, so I think the average is about 50, which is hardly a load, but it is still inefficient...
I get a lot of notifications because it's a talk app.

I heard that SQLite is maintained as a native, so I thought about not closing it, but
As expected, if you don't close it, a memory leak will occur...

How is it best to maintain, manage, and close SQLite for services that handle notifications?

android

2022-09-30 11:54

1 Answers

I thought about it for a moment.
If the notification settings fit the life cycle of the application class, would it be necessary to cache the settings at that scope and browse sqlite each time?
However, cache control is required and seems to be over-optimized.
I think it would be more appropriate to finish quickly without taking any strange life-prolonging measures.


2022-09-30 11:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.