Can I combine my code into some kind of “global activity”?

后端 未结 3 1375
再見小時候
再見小時候 2020-12-06 15:08

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

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 15:43

    You can create a class that extends Activity and then extend the CustomActivity to all the Activity Class like this.

    public abstract class CustomActivity extends Activity{
    
        public abstract void initComponents();  // you can create a abstract method
        public abstract void addListner();       // you can create a abstract method
    
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
    
             if ((keyCode == KeyEvent.KEYCODE_BACK)) {
                  // your stuff here....
                }
            return true;
        }
    }
    

    Now you can extend this class where you want to extend any class with Activity.

提交回复
热议问题