简体   繁体   中英

Android how to make back button perform action on a the first click?

I have back button reprogrammed like that:

@Override
public void onBackPressed() {
    returnManager();
}

The problem that I am facing is that when I touch it for the first time it doesn't do anything. After the first time, it works as intended and calls returnManager. Then, if I press some other buttons on the screen and press back again, it doesn't do anything for the first time but works on next touches. Is there anything I am missing here?

A strange solution:

int calls = 0;

@Override
public void onBackPressed()
{
    calls++;
    if(calls==1)
    {
        returnManager();
        returnManager();
    }
    else
    {
        returnManager();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM