Intent 启动新 Activity 的速度非常慢 :(

Intent is very slow to launch a new Activity :((Intent 启动新 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 的速度非常慢 :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)