What happens to Activities/Services when phone goes to sleep/standby mode?

前端 未结 4 1304
深忆病人
深忆病人 2021-02-20 15:39

What happens to android application and activities and services that belongs to application when the phone/AP goes to sleep mode?Will the framework destroy Activities and Servic

4条回答
  •  太阳男子
    2021-02-20 16:17

    In case of device sleep, activity's `onPause()' will be called. Read activity lifecycle to understand this.

    OS only kills the process when memory/resources are low. Activities are killed first, services are only killed as last resort.

    But there is no guarantee they will not be killed. This is why you should rely on system services to call you when you need some work done: use AlarmManager to do call your code periodically or use listeners to notify you of system changes (gps, network, etc..)

提交回复
热议问题