Intent is very slow to launch a new Activity :((Intent 启动新 Activity 的速度非常慢 :()
问题描述
我有一段 Intent 代码:
I have this piece of code for an Intent:
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(new ComponentName(packToLaunch, nameToLaunch));
startActivity(i);
这基本上会根据我传递给它的包名称启动一个新活动.有时,启动此新活动最多需要 5 秒钟.有没有办法加快这个过程?当我有一个仍在运行的应用程序时,甚至需要这么长时间.请帮忙...
This basically launches a new activity based on the package name that I pass to it. Sometimes, it takes up to 5 seconds to launch this new Activity. Is there any way to speed this process up? It even takes this long when I have an app that is still running. Please help...
推荐答案
Android 似乎故意延迟了服务中 Activity 的启动在您按下 HOME 按钮后.(使用 BACK 按钮时一切正常.)甚至发布了问题 https://code.google.com/p/android/issues/detail?id=4536 但是它已经过时了.
It looks like Android intentionally delays launch of activity from service right after you press HOME button. (When using BACK button everything is OK.) There was even issue posted https://code.google.com/p/android/issues/detail?id=4536 however it got obsolete.
我试图在 Android 源代码中搜索延迟的实际实现,但失败了.您可能需要检查以下问题,因为它说明了完全相同的问题并提供了更多见解:在按下 HOME 按钮后从服务开始活动,没有 5 秒延迟
I tried to search actual implementation of the delay in Android source, but failed. You might want to check the following question as it states pretty same issue and gives some more insights: Starting an activity from a service after HOME button pressed without the 5 seconds delay
这篇关于Intent 启动新 Activity 的速度非常慢 :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Intent 启动新 Activity 的速度非常慢 :(
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01