Changing the Priority

This section describes how an application (internal or third-party) can change its priority by using OOM Monitor APIs.

An application which is processing a task in the background can change its priority at runtime to protect itself from being closed by the OOM Monitor. For example:

  • Music Player playing music in the background

  • Download Manager downloading a file in the background

If an application is processing a task for the user in the background, the application is said to be Busy and the OOM Monitor must not close a Busy application. An application can declare itself to be Busy using ROomMonitorSession::SetOomPriority(EOomPriorityBusy) method. When the application finishes its background job and becomes idle, it should change its priority to Normal.

  1. Create an OOM Monitor session
    ROomMonitorSession ioomMonitorSession;
    CleanUpClosePushL(ioomMonitorSession);
    User::LeaveIfError(ioomMonitorSession.Connect());
    
  2. Set the priority for the application to Busy before performing the background task
    iOomMonitorSession.SetOomPriority(ROomMonitorSession::EOomPriorityBusy);
    DoCriticalBackgroundProcessingL();
    
  3. Set the priority for the application to Normal after the task is completed.
    iOomMonitorSession.SetOomPriority(ROomMonitorSession::EOomPriorityNormal);
    
  4. Close the session.
    iOomMonitorSession.Close();