Reputation: 313
I created an application which runs on background in every 3 minutes and do some calculation and update data on sqlite database.my app is consuming more battery after installing this app. so can you please update me how to create app for optimization battery life.
Thanks.
Upvotes: 1
Views: 1557
Reputation: 710
Yes offcourse it is possible, your application is draining battery because you are running your service all the time but instead of that .................................................................................................................... The best practice is to create a AlarmManager context using PendingIntent, Now for every 3 min set an alarm. create a BroadcastReceiver which receives alarm after every 3 minutes. NOW.... from that Receiver start your service do calculations on that service and save it into database. after saving clear() all the data of intents, database objects and also close the database connections. and after doing all these things call stopService() to stop your service immediately. This makes your application to startService() only after every 3 mins and after doing all calculations it stops service. check with this and i am sure you will not get any problem regarding battery because your service will run for max 2 secs on every 3 mins :)
Upvotes: 2