I have an app in store, and a few users said that the app uses either too much battery, or it his hig mb in resources(10 or 20mb+). In my device its fine and on a few devices if seen it its fine.
I use an sms broadcast receiver to read all the incomming sms, and if i see any message i want to process i read it etc. So basically the service needs to run all the time so i dont lose any message that might come.
Is there a way to optimize this or to make the code lighter if its possible so that all users are ok with this? I know it might differ from device to device and from android version to version but giving it a shot would be good.
I didnt try anything yet as i dont have a clue what could be the problem or if there is actually one. And Ive searched a little and people say that the service shouldnt run all the time and should restart a few times or close it when not needed. But my sms receiver needs to run all the time.
Any ideas or anything i should check for?
My service by the way is startForeground, so it doesnt turn off from android.
Thank you for your time
You don't need a Service running constantly to receive incoming SMS. Simply register your BroadcastReceiver class in the manifest, and start an IntentService in
onReceive()
to handle whatever processing you need to do. The IntentService will stop itself when it is finished. Your app does not need an active component for a statically registered Receiver to be delivered theSMS_RECEIVED
broadcast. The Receiver will be started by the system when delivering the Intent.