Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Q] Listener problem

OP Deyaz

12th June 2014, 11:23 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
7 posts
Join Date:Joined: Jun 2014
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?
13th June 2014, 12:14 AM   |  #2  
Senior Member
Flag Cologne
Thanks Meter: 219
 
190 posts
Join Date:Joined: May 2013
More
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.
13th June 2014, 12:17 AM   |  #3  
OP Junior Member
Thanks Meter: 0
 
7 posts
Join Date:Joined: Jun 2014
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 by Deyaz; 13th June 2014 at 12:22 AM.
13th June 2014, 01:39 AM   |  #4  
Jonny's Avatar
Forum Moderator
Flag Cheshire
Thanks Meter: 8,273
 
8,122 posts
Join Date:Joined: Jul 2011
Donate to Me
More
Quote:
Originally Posted by Deyaz

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.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes