[Q] Listener problem

Search This thread

Deyaz

Member
Jun 11, 2014
7
0
Hi,

I want my app to start, after the back button was pressed 3x.
So I got this class which is executed in the Launcher.

Code:
public class KeyManager extends Activity {
    
		@Override
       public boolean onKeyDown(int keyCode, KeyEvent event) {
           if(KeyEvent == "Back key"){
                 Log.e("KM", "PRESSED!!!!!"+keyCode);
           }

           //return super.onKeyDown(keyCode, event);
           return false; 
       }
}

This code works, if it s implemented in the launcher class, but it does not work, if the app is in the background. How or which key listener do I need for listening to background keys or more if the app is working only in the background?
 

giuliomvr

Senior Member
May 16, 2013
189
235
Cologne
Of course it doesn't work when being background. These events aren't sent to the activitiy if it's not in the foreground, and as far as I know even services can't react to them.
 

Deyaz

Member
Jun 11, 2014
7
0
Well, ok so that is the problem. But I think it should be possible to solve that as some apps also react if for example the browser is being opened etc. Also, Samsung user might know, by clicking 2x the home button the app S Voice opens. And it should not be a system app, but just a usual one.
Maybe something like a global key listener is available? Unfortunately I couldnt find anything referring to that, yet.
 
Last edited:

Jonny

Retired Forum Moderator
Jul 22, 2011
9,293
9,616
Well, ok so that is the problem. But I think it should be possible to solve that as some apps also react if for example the browser is being opened etc. Also, Samsung user might know, by clicking 2x the home button the app S Voice opens. And it should not be a system app, but just a usual one.
Maybe something like a global key listener is available? Unfortunately I couldnt find anything referring to that, yet.

The Samsung S voice example is a really bad example to use because that's just code implemented in TouchWiz's launcher, I'm guessing its a timer that listens for 2 presses of the home button within a set time, if 2 presses are registered in the given time-frame, S Voice is launched via intent, if not then the default action for the home button is taken.