gpt4 book ai didi

android - 从服务启动 Activity 花费的时间太长

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:20:55 26 4
gpt4 key购买 nike

我有一个 Service,当一个函数给我 true 时,它会启动一个新的 Activity 但它需要大约 5 秒.. .

我读过这个issue ,我在 StackOverflow 上找到了这个例子来“避免”这个错误..

Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}

但遗憾的是,它并没有更快地启动 Activity,我不需要立即(如果可能的话更好),但我不想等待 +5 秒来启动新的 Activity,你知道有什么技巧可以避免这种情况吗?

我正在使用 PendingIntent 因为我发现有人说它应该可以解决这个问题: Starting an activity from a service after HOME button pressed without the 5 seconds delay

注意事项

如果我按下 后退按钮,它会自动启动,0 延迟,但我正在寻找按下 home 按钮

最佳答案

我还不能到处评论,所以我把这个类似问题的解决方案作为答案

After much digging, found out the cause of the problem. Apparently it's not a bug, it is a feature which does not allow Services or BroadcastReceivers to launch activities for up to 5 seconds after home button is pressed. No easy way to overcome this.

More info here: https://code.google.com/p/android/issues/detail?id=4536

I replaced the activity with a Window added to the window manager of the running service. This does not cause any delay.

来源链接 Stackoverflow

关于android - 从服务启动 Activity 花费的时间太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47124188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com