How to run code periodically in the background in Tizen 5.5?

259 Views Asked by At

I need to run a code every x minutes and show a notification if needed.

How can I run a code in the background periodically while the app is closed?


So far what I've reached to is that I lock the CPU and call a timer to run periodically. The problem with this is that it drains the battery and the watch shows a notification suggesting to close the app.

public static void LockCpu()
{
    Power.RequestLock(PowerLock.Cpu, 0);
}

public static void ReleaseCpu()
{
    Power.ReleaseLock(PowerLock.Cpu);
}

It's for Tizen .NET for wearable watches.

Thanks.

1

There are 1 best solutions below

0
benignvirus On

You can use the Alarm API to run code periodically. https://docs.tizen.org/application/dotnet/guides/alarm/alarms/ https://docs.tizen.org/application/dotnet/api/TizenFX/API7/api/Tizen.Applications.AlarmManager.html

To prevent battery drain, that is not guaranteed to be accurate.