Intent 启动新 Activity 的速度非常慢 :( [英] Intent is very slow to launch a new Activity :(

查看:36
本文介绍了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 的速度非常慢 :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆