StopSwitchDelay - Remove 5s Delay To Open Apps After Pressing Home Button

Search This thread

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
Last edited:

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
Im not sure what kind of delay are you talking about?
After pressing the home button, there's a five seconds delay set by Android.

During that time, if an activity (e.g. Switchr) tries to start another activity, that action will be delayed. On KitKat and higher, I think it shows you a warning when that happens (a "Loading app..." toast.)
(The delay is reset when you open an app from the launcher or task switcher, too)

If you've never encountered the issue then you most likely don't need this module.
 
Last edited:

pitastrudl

Senior Member
May 15, 2011
1,789
574
Ljubljana
slo-android.si
After pressing the home button, there's a five seconds delay set by Android.

During that time, if an activity (e.g. Switchr) tries to start another activity, that action will be delayed. On KitKat and higher, I think it shoes you a warning when that happens (a "Loading app..." toast.)
(The delay is reset when you open an app from the launcher or task switcher, too)

If you've never encountered the issue then you most likely don't need this module.

Now that you mention it, i have encountered a problem like that, but i've only seen it in a few apps. Also while using switchr, the problem occured randomly(or so it seemed). an example for the app is Castle Clash. But I do not recall a toast showing "loading app". Would the delay also apply to Tasker? I will try out the module and report. Maybe the problem is fixed in a custom rom im using(Slimkat, AOSP).
 

Pkt_Lnt

Inactive Recognized Contributor
Dec 26, 2011
7,894
5,804
SLO
So that is what has been driving me crazy and I had no idea. Seemed like lags and hangs. Thanks!
 

Soe Min Thu

Senior Member
Nov 18, 2013
103
10
Sounds Great!!

I'm using side bar app to open some apps and I have encountered that many times but I didn't know it's concerning with home button and I thought it was just a bug of the sidebar app!! Great!! However, can't be that was added in Android OS originally due to necessary?? Any Risks after this module??
 

GermainZ

Inactive Recognized Developer / Retired Forum Mod
Aug 3, 2012
6,170
8,805
@GermainZ can we get gingerbread support plz?
Should work fine on Gingerbread, I'll lower the SDK version later.
However, can't be that was added in Android OS originally due to necessary?? Any Risks after this module??
I can't see any. If a malicious app wants to override your home button this way it could use a background service to bypass the delay anyway. As to why it was added, ask the Google engineers.
 
  • Like
Reactions: killoid

_jis_

Senior Member
Feb 5, 2012
1,469
530
After pressing the home button, there's a five seconds delay set by Android.
During that time, if an activity (e.g. Switchr) tries to start another activity, that action will be delayed. On KitKat and higher, I think it shoes you a warning when that happens (a "Loading app..." toast.)
As a long time user of SwipePad I know this delay and connected toast message very well. Thank you for this module!
As to why it was added, ask the Google engineers.
Normally Android system force a 5s delay after you click the home button in order to give home application some priorities to finish switching. But I think that 5s was huge overkill on any today's decent hardware.
 
  • Like
Reactions: GermainZ

dragonnn

Senior Member
Oct 16, 2011
1,136
861
Wow! This should be in Android by default, now task switching is much faster! Big thanks.

Wysłane z mojego C6603 przy użyciu Tapatalka
 

ganeshp

Senior Member
Mar 15, 2012
5,496
3,259
Hyderabad
wow this is a great module.
switching is pretty fast now with this module + switchr on my nexus 5..
pretty awesome work I would say.
Thanks for this.

ALL HAIL XPOSED!!!

edit: posted it in /r/xposed and /r/android of reddit (can't contain my happiness!)
 
Last edited:

Hopper8

Senior Member
Sep 17, 2012
2,346
3,744
Awesome work GermainZ! I didn't even know this was an 'intentional' feature. Ah well, no more "Loading App" toast for me :D
 

Top Liked Posts

  • There are no posts matching your filters.
  • 93
    Introduction
    This is a very simple module that removes the 5 seconds delay preventing you from opening apps (other than from the launcher) after pressing the home button.
    More detailed explanation | Even more detailed explanation

    Requirements:
    Xposed Framework

    Source:
    https://github.com/GermainZ/StopSwitchDelay

    Download:
    http://repo.xposed.info/module/com.germainz.stopswitchdelay

    Thanks:
    rovo89 and Tungstwenty for the Xposed Framework.
    12
    ok np i just want you know that normal Timeout is (0,5 seconds) for keys

    Code:
    private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;

    and the problem caused by keyguard ;)

    and i dont have this issue on all my devices
    That's for another thing, if you check the source code of ActivityManagerService, you'll see this:
    Code:
    ...
        // Amount of time after a call to stopAppSwitches() during which we will
        // prevent further untrusted switches from happening.
        static final long [COLOR="DeepSkyBlue"]APP_SWITCH_DELAY_TIME[/COLOR] = 5*1000;
    ...
    
        /**
         * The time at which we will allow normal application switches again,
         * after a call to {@link #stopAppSwitches()}.
         */
        long mAppSwitchesAllowedTime;
    ...
    
        public void [COLOR="Red"]stopAppSwitches()[/COLOR] {
            if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
                    != PackageManager.PERMISSION_GRANTED) {
                throw new SecurityException("Requires permission "
                        + android.Manifest.permission.STOP_APP_SWITCHES);
            }
            
            synchronized(this) {
                mAppSwitchesAllowedTime = SystemClock.uptimeMillis()
                        + [COLOR="DeepSkyBlue"]APP_SWITCH_DELAY_TIME[/COLOR];
                mDidAppSwitch = false;
                mHandler.removeMessages(DO_PENDING_ACTIVITY_LAUNCHES_MSG);
                Message msg = mHandler.obtainMessage(DO_PENDING_ACTIVITY_LAUNCHES_MSG);
                mHandler.sendMessageDelayed(msg, APP_SWITCH_DELAY_TIME);
            }
        }
    ...
    This module makes the stopAppSwitches method do nothing (the source code is available and very simple.)
    This method is (mainly) called from com.android.internal.policy.impl.MidWindowManager:
    Code:
    ...
    
        /**
    * A home key -> launch home action was detected. Take the appropriate action
    * given the situation with the keyguard.
    */
        private void launchHomeFromHotKey() {
            // no keyguard stuff to worry about, just launch home!
            try {
                ActivityManagerNative.getDefault()[COLOR="Red"].stopAppSwitches()[/COLOR];
            } catch (RemoteException e) {
            }
            mContext.startActivity(mHomeIntent);
            sendCloseSystemWindows();
        }
    ...
    
        /**
    * goes to the home screen
    * @return whether it did anything
    */
        boolean goHome() {
            if (false) {
                // This code always brings home to the front.
                try {
                    ActivityManagerNative.getDefault().[COLOR="Red"]stopAppSwitches()[/COLOR];
                } catch (RemoteException e) {
                }
                mContext.startActivity(mHomeIntent);
            } else {
                // This code brings home to the front or, if it is already
                // at the front, puts the device to sleep.
                try {
                    ActivityManagerNative.getDefault().stopAppSwitches();
                    int result = ActivityManagerNative.getDefault()
                            .startActivity(null, mHomeIntent,
                                    mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
                                    null, 0, null, null, 0, true /* onlyIfNeeded*/, false);
                    if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) {
                        return false;
                    }
                } catch (RemoteException ex) {
                    // bummer, the activity manager, which is in this process, is dead
                }
            }
            sendCloseSystemWindows();
            return true;
        }
    You can check those (and more) yourself if you want to.

    As for not having this problem on your device, check the third post for an explanation, you most likely haven't encountered it.
    10
    Im not sure what kind of delay are you talking about?
    After pressing the home button, there's a five seconds delay set by Android.

    During that time, if an activity (e.g. Switchr) tries to start another activity, that action will be delayed. On KitKat and higher, I think it shows you a warning when that happens (a "Loading app..." toast.)
    (The delay is reset when you open an app from the launcher or task switcher, too)

    If you've never encountered the issue then you most likely don't need this module.
    4
    Confirmed to be working device seems a lot more responsive. This is still not published on xposed not sure why 1.1 is listed and the one in here is 1.2
    Crap, I keep forgetting. This weekend!

    Edit: done ❤
    4
    @GermainZ can we get gingerbread support plz?
    I've lowered the minSdkVersion to support Gingerbread, please test it.