监听home键广播启动Activity会延迟5s,但是通过PendingIntent.send()方法启动Activity可以立即启动?查看源码只追到Activity启动会延迟5秒的原因,未追查到PendingIntent
.send()可以立即启动Activity的原因,不知是否有小伙伴解决过这个问题。
private BroadcastReceiver homeKeyReceiver = new BroadcastReceiver() {
private static final String SYSTEM_DIALOG_REASON_KEY = "reason";
private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
@Override
public void onReceive(Context context, Intent intent) {
if (TextUtils.equals(intent.getAction(), Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
if (TextUtils.equals(intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY), SYSTEM_DIALOG_REASON_HOME_KEY)) {
Intent secondIntent = new Intent(FirstMainActivity.this, SecondMainActivity.class);
secondIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
| Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(FirstMainActivity.this, 0,
secondIntent, 0);
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
}
}
};
如果在onReceive方法通过startActivity启动SecondMainActivity,会延时5秒启动。
麻烦告知一下PendingIntent.send()为何能够绕过这个延时5秒的限制,特别感谢。