Intent is very slow to launch a new Activity :(

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);

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...


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.

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

链接地址: http://www.djcxy.com/p/52490.html

上一篇: f(n)= n ^ log(n)复杂多项式或指数

下一篇: 意图是非常缓慢推出新的活动:(