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

查看:35
本文介绍了启动新活动的意图非常慢:(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段用于 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 在您按下 HOME 按钮后立即延迟从服务启动活动.(使用后退按钮时一切正常.)甚至发布了问题 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 源代码中搜索延迟的实际实现,但失败了.您可能想检查以下问题,因为它陈述了完全相同的问题并提供了更多见解:在没有 5 秒延迟的情况下按下 HOME 按钮后从服务启动活动

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

这篇关于启动新活动的意图非常慢:(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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