Thursday, 15 January 2015

android - Set a task priority or disable a task run, when resources are low -



android - Set a task priority or disable a task run, when resources are low -

i running background timer task bit of computational work every hour. question if can somehow set task run in lower priority others. alternatively, ok skip run of task if resources low (say, memory below 50%, battery below 30%, , cpu above 60%). it's not mandatory compute every time, long steady run.

can suggest me way this? don't want have app mess user's experience, when users playing game, listening music, watching film etc.

there multiple ways conserve resources:

do work in thread on phone call setpriority(thread.min_priority) after creating it. way thread scheduled lowest priority. wake thread every hour.

consider waking app work using alarmmanager.setinexactrepeating(alarmmanager.interval_hour). conserves energy because "system can adjust alarms' delivery times cause them fire simultaneously, avoiding waking device sleep more necessary."

you can utilize activitymanager.getmymemorystate() figure out if scheme memory tight. if field lasttrimlevel of activitymanager.runningappprocessinfo object filled phone call trim_memory_running_critical or trim_memory_running_low should skip running task.

android performance timertask

No comments:

Post a Comment