Android 向Application对象添加Activity监听
可以建立对象把Application.ActivityLifecycleCallbacks接口中的函数实现,并利用public void registerActivityLifecycleCallbacks (Application.ActivityLifecycleCallbacks callback)函数向application添加代理对象。
比如以下代码,在本程序的全部activity的resume时都会调用。
@Override public void onActivityResumed(Activity arg0) { System.out.println("onActivityResumed..................."); System.out.println("~~~~~~~~~~~~test activity is "+arg0.getClass()); if( arg0.getClass() == PasscodeUnlockActivity.class ) return; System.out.println("onActivityResumed.........111111.........."); if( ( this.appLockDisabledActivities != null ) && Arrays.asList(this.appLockDisabledActivities).contains( arg0.getClass().getName() ) ) return; System.out.println("onActivityResumed........22222..........."); if(mustShowUnlockSceen()) { //uhhh ohhh! System.out.println("show lock........4444.........."); Intent i = new Intent(arg0.getApplicationContext(), PasscodeUnlockActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); arg0.getApplication().startActivity(i); return; } }