Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,809,687 Members 41,578 Now Online
XDA Developers Android and Mobile Development Forum

[Q] Listener problem

Tip us?
 
Deyaz
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 7
Join Date: Jun 2014
Default [Q] Listener problem

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
Old
#2  
Senior Member
Thanks Meter 213
Posts: 190
Join Date: May 2013
Location: 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
Old
(Last edited by Deyaz; 12th June 2014 at 11:22 PM.)
#3  
Junior Member - OP
Thanks Meter 0
Posts: 7
Join Date: 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.
 
Jonny
Old
#4  
Jonny's Avatar
Forum Moderator
Thanks Meter 8,002
Posts: 7,981
Join Date: Jul 2011
Location: Cheshire

 
DONATE TO ME
Quote:
Originally Posted by Deyaz View Post
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.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes