Is there any global activity on Android such that I put my code in that one activity, and it affects all activities in my project? This occurs to me because the same code is
I would suggest extending activity as @Lalit Poptani suggested. Since that is been said i could provide an alternative way for this to work.
You can create an interface that you implement in your activity including public boolean onKeyDown(int keyCode, KeyEvent event) (just to keep you a reminder you have to implement the code to your activity)
Create a global (static) class/function that performs the onKeyDown operations.
public class ButtonHandler{
public static boolean handleButton(Context context,int keyCode, KeyEvent event){
..... your code here
}
}
and just call return ButtonHandler.handleButton(getApplicationContext(),keycode,event) to your onKeyDown methods.
But still .. overriding activity is the best way to go. If for some reason you don't want to extend this is the way to go