49557

How to optimize sms background service for battery and resources

Question:

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

Answer1:

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 the SMS_RECEIVED broadcast. The Receiver will be started by the system when delivering the Intent.

Recommend

  • How to achieve Terraria/Starbound 2d lighting?
  • Check with jQuery if a value in an input element was entered
  • Inspect Element Using System.Windows.Forms.WebBrowser
  • set palette color to blue in gnuplot
  • Dynamic UI from JSON object
  • What is the difference between CacheStoreMode USE and REFRESH
  • How to have a difference in week units between two days (even if they're close but belong to di
  • Wiring top-level DAGs together
  • How to Optimize mach_msg_trap
  • if clause in bigquery
  • How can I get a specific version of a dataset row?
  • Gforce min not supported for character in data.table
  • FragmentActivity with a Fragment Containing a MapView
  • Always require certain dependencies in RequireJS
  • Does the MySQL IN clause execute the subquery multiple times?
  • Deduce parent class of inherited method in C++
  • Python pandas melting data to multiple columns and coulmn names in another column
  • Hide HTML elements without javascript, only CSS
  • Transactional Create with Validation in ServiceStack Redis Client
  • Disable Enter in editText android
  • Cannot resolve symbol 'MyApi'
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • NetLogo BehaviorSpace - Measure runs using reporters
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Perl system calls when running as another user using sudo
  • Deserializing XML into class C#
  • Release, debug version and Authorization Google?
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • How to include full .NET prerequisite for Wix Burn installer
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • costura.fody for a dll that references another dll
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize