An Application life cycle needs to be managed.
When managing the app life cycle, there are many things that need to be taken into account, such as the app’s battery consumption, use of memory, behaviors in different states and more. It is important to configure each of the stages in the app lifecycle precisely the way you want to shape the user experience.
You should consider how the app behaves when it is not the main app that is running in the foreground. For example, it is common for your app to pause all of its activity when minimized, because the user wouldn’t be able to interact with the User Interface(UI). In rare instances, you may want the app to continue running in a background state, doing a background task such as playing an audio stream. This can be done by giving the following permission in the project’s bar-descriptor.xml file. Use this permission sparingly and only when your app must perform processing in the background.
<permission> run_when_backgrounded </permission>
Even in the background state, if your app is given the permission to continue running, it can consume processing power and resources, unnecessarily consume power. Only use the run_when_backgrounded permission when it is absolutely necessary. Restricting your use of this permission helps to ensure that users have an optimal experience with the devices. For more permissions that you can give to your app, see App permissions.
Another consideration is the management of the screen display of your app amid state transitions. Normally, the app is affected by the user setting that causes a device to go into a standby mode, turning off the backlight and deactivating the app that was previously active. However, you can use the flag SCREEN_IDLE_MODE_KEEP_AWAKE with the function screen_set_window_property_iv() to prevent your app from automatically going into standby mode. The following code snippet shows you how to prevent an app from going into standby mode.
int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
screen_set_window_property_iv(screen_win,
SCREEN_PROPERTY_IDLE_MODE,
&idle_mode);
This code should only be used when it is absolutely necessary for your app, such as when playing a video. However, even with this implemented, the app enters the standby mode whenever the user puts the device to sleep.
Another display management with regards to state changes is the rendering. When the app is shown as a thumbnail, and when your app is invisible, you likely want to stop rendering and show the screenshot of the last image before the app was paused. For details of each of the states, see Various States.