场景
按BACK键后重启速度很快,按Home键后约5秒才能看到。
官方
谷歌Android API Guides为避用户毫不知情时突中断用户进行工作而要求不于后台(包括Service和BroadcastReceiver)启Activity。
That is, don't call startActivity() from BroadcastReceivers or Services running in the background. Doing so will interrupt whatever application is
currently running, and result in an annoyed user. Perhaps even worse, your Activity may become a "keystroke bandit" and receive some of the input
the user was in the middle of providing to the previous Activity. Depending on what your application does, this could be bad news.
分析
延迟5秒在com.android.server.am.ActivityManagerService
之stopAppSwitches()
中,系统级应用获android.permission.STOP_APP_SWITCHES
后将不调该法延迟通后台启Activity。原生Phone应用即一获android.permission.STOP_APP_SWITCHES
权限系统级应用,有来电时一从后台启Activity突现于用户面前警醒用户新来电。
解决
一
- root手机
- AndroidManifest.xml添
android.permission.STOP_APP_SWITCHES
权限 - push所开发的应用程序到手机/system/app目录中