I have an application that keeps tracks of other applications screentime. I have a service which is supposed to give a notification after the user has spend X time on a specific application. To keep track of other applications, I have used a Service. When my own application is open, the details of other applications screen time is shown correctly, but when my app goes in the background, the details aren't updated (they remain the same as when my own application was open), but as soon as I reopen my application, the details get updated. Why isnt the UsageStatsManager working properly while being in the background?
var appList = usm.queryUsageStats(
UsageStatsManager.INTERVAL_DAILY,
System.currentTimeMillis() - 1000 * 3600 * 24,
System.currentTimeMillis()
)
I have the following code in my manifest
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<service android:enabled="true" android:name=".MyService" />
</application>