alarm icon indicating copy to clipboard operation
alarm copied to clipboard

Battery usage of the application

Open dev-chetan opened this issue 10 months ago • 23 comments

Thanks for your effort and great work. Alarms are ringing as expected on the iOS however I noticed huge jump in the battery usage of the application. If I am understanding correct than we are keeping application active in background and due to that battery usage is high so as a workaround can we send a silent notification just before the alarm time and make our application active. This way we will not have to keep our application active all the time, and we can save some battery. Please share your thoughts on this.

dev-chetan avatar Oct 11 '23 05:10 dev-chetan

Hi @dev-chetan,

I might be mistaken but I'm pretty sure that sending a silent notification before alarm rings won't wake the app.

Do you have more information on the amount of battery used ? You can see details in Settings > Battery.

gdelataillade avatar Oct 12 '23 13:10 gdelataillade

Sure, I can research with silent notification. I did checked in setting and its using around 60%-70% battery if we set alarm for morning as it will keep application active for whole night.

dev-chetan avatar Oct 12 '23 14:10 dev-chetan

The 70% you see in your iOS battery settings for an app means that app used 70% of the total battery consumed during that period, not that it used up 70% of your battery’s total capacity.

gdelataillade avatar Oct 12 '23 15:10 gdelataillade

Thanks for the quick response, When I don't set the Alarm application is hardly using 10% of battery for my app, For Alarm testing I didn't touch the application until the Alarm rang. it's a noticeable difference in battery usage between application with Alarm and without Alarm. 

dev-chetan avatar Oct 12 '23 17:10 dev-chetan

After full day of 100 --> 0% battery, I experienced 36% of iPhone 13 Pro battery from only background alarm app usage (19 hours total)

Brandonfas avatar Oct 12 '23 17:10 Brandonfas

Hi @Brandonfas @dev-chetan

Could you share a screenshot of this screen please ? It could really help.

If relevant, please share the last 10 days, last 24 hours and a specific hour.

IMG_3813

gdelataillade avatar Oct 23 '23 12:10 gdelataillade

@gdelataillade here are 2 screenshots from 24 hours, at the moment it’s difficult to do a longer test as battery life gets cut almost in half, reducing functionality of phone significantly

you’ll notice that 3 hours of watching videos on Instagram is still a significantly less battery than current alarm background fetch

IMG_9109 IMG_9108

Brandonfas avatar Oct 23 '23 15:10 Brandonfas

Hi @Brandonfas

Thanks for the screenshot. I'll think about a way to use less battery, but honestly I don't have any idea in mind...

gdelataillade avatar Oct 23 '23 18:10 gdelataillade

Everyone that has battery issues please share your battery usage.

gdelataillade avatar Oct 23 '23 18:10 gdelataillade

@gdelataillade I have the same problem. When I look at battery utilization in my iOS settings, the apps that are using alarms are taking up over 60%.

My app does not require the alarm to be active all the time. Clicking on a specific [start button] will activate the alarm and allow me to activate the alarm on that page.

I want the alarm to be deactivated in the background again when the [end button] is pressed. Calling Alarm.stopAll() when I press the [end button] does not disable the alarm in the background and it is consuming battery.

synstin avatar Nov 19 '23 01:11 synstin

IMG_1490 IMG_1491

@gdelataillade Screenshot of iOS battery usage. The alarm is constantly draining the battery even though it is not active.

In the second screenshot, you can see that the battery is draining at 4-5am, even though the smartphone is not being used and there is no active alarm.

Before I went to bed, the battery was at 97%, but when I checked it in the morning, it was down to less than 50%.

If there is no active alarm, we need a way to stop background tasks from draining the battery. For example, might need something like this

// When need to use alarms in app
Alarm.init()

// When alarms are no longer used in the app
Alarm.dispose()

In my opinion, this is very critical and users will not use the app if it is constantly draining battery like this.

I am using version 2.1.1 and tested on iPhone14 iOS17. I'll test and let you know if this is the same on Android.

synstin avatar Nov 19 '23 03:11 synstin

Hi @synstin

Thanks for your feedback.

Alarm background process is supposed to be automatically disposed when all alarms are stopped. Maybe there is a memory leak somewhere. I'll investigate this as soon as I find the time.

gdelataillade avatar Nov 19 '23 13:11 gdelataillade

I use a silent audio player to keep the alarm app active in the background, but only when an alarm is scheduled. This method is similar to what's used in other alarm apps like Alarmy. They seem to optimize battery life by playing the silent audio briefly, perhaps for 1 second every 10 seconds, instead of continuously. I plan to implement this intermittent playback method in my app as well to see if it helps save battery life.

gdelataillade avatar Nov 19 '23 13:11 gdelataillade

@gdelataillade

Alarm.ringStream.stream.listen((_) => Alarm.stopAll());

I did stopAll() when I received the alarm completion event on the stream and the battery leak went away.

synstin avatar Nov 20 '23 06:11 synstin

Hello everyone, I had the opportunity to test the package by taking a solution on the market as a comparison (alarmy). You can see on the screenshots that the consumption of the two alarms is identical. Unfortunately, Apple's current policy does not allow you to call an alarm with the application killed, and the need to keep an activity in the background is costly in terms of energy. Congratulations once again on all your hard work!

IMG_0030 IMG_0031 IMG_0032

wayupdev avatar Nov 23 '23 19:11 wayupdev

I use a silent audio player to keep the alarm app active in the background, but only when an alarm is scheduled. This method is similar to what's used in other alarm apps like Alarmy. They seem to optimize battery life by playing the silent audio briefly, perhaps for 1 second every 10 seconds, instead of continuously. I plan to implement this intermittent playback method in my app as well to see if it helps save battery life.

Would it be more optimal to check 1 second every 1 minute? Since alarms are set at a minute level anyway

That would be 1/60th of background audio playing compared to existing application battery life

If not, no problem. Just a thought!

Brandonfas avatar Nov 23 '23 19:11 Brandonfas

Hi @Brandonfas

Thanks for your suggestion to reduce the silent audio playback to 1 second per minute. It's an interesting idea, but I need to consider the limitations of my current approach. While it does consume a significant amount of battery, it's similar to methods used by established apps like Alarmy. This similarity suggests that under current iOS constraints, this might be one of the more viable options. As a solo developer continuously learning about iOS development, implementing major changes to background task management could lead to unexpected challenges, particularly given the complex nature of iOS's handling of such tasks. Although I'm aware that my method isn't the most battery-efficient, altering the playback frequency could risk the app being terminated prematurely by iOS. I'll stick with the existing method for now, but I'm definitely open to exploring more efficient solutions as I enhance my understanding of iOS development.

Contributions, research, feedback, or any help would be greatly appreciated and could significantly aid in improving the package in future releases.

gdelataillade avatar Nov 24 '23 11:11 gdelataillade

Possibly give the user a choice to configure the silent audio playback, some apps need alarm at a minute level accuracy some need alarm at a sec level,

with this knob, developers will know why its eating battery and experiment with it(vs having to reach out to you)

no-1ne avatar Dec 04 '23 00:12 no-1ne

I use a silent audio player to keep the alarm app active in the background, but only when an alarm is scheduled. This method is similar to what's used in other alarm apps like Alarmy. They seem to optimize battery life by playing the silent audio briefly, perhaps for 1 second every 10 seconds, instead of continuously. I plan to implement this intermittent playback method in my app as well to see if it helps save battery life.

I've done some additional research into Alarmy and apparently they went from continuous to 1 second every 10 seconds in version 6.63.0 for the exact purpose of battery draining. Is this something that could be possibly implemented?

I love this application, only limitation seems to be battery drain in terms of long-term usage and user satisfaction. Thanks again for all of the hard work you've done!

Brandonfas avatar Dec 14 '23 21:12 Brandonfas

Hi @Brandonfas

Thank you for your research ! Could you provide the link where you read about the "1 second every 10 seconds" please ?

It's probably something I could implement in the plugin but it won't be easy to be honest. Do you see a significant difference of the battery usage between Alarmy and my alarm plugin ?

gdelataillade avatar Dec 15 '23 11:12 gdelataillade

@gdelataillade I've suddenly noticed a huge increase in battery usage on IOS. I am using version 3.0.5.

synstin avatar Jan 18 '24 12:01 synstin

@synstin that's weird I did not make any changes on iOS on the background process part in the last weeks... could you share some of your battery usage ?

gdelataillade avatar Jan 18 '24 15:01 gdelataillade

@gdelataillade It seems to happen after updating the version from 3.0.2 to 3.0.4 or 3.0.5. I'll make some more observations and get back to you. As always, thanks for the quick feedback.

synstin avatar Jan 18 '24 23:01 synstin