Talk about a common function of a project, friend League statistical function
For example, a project has a lot of modlue, each inside Modlue have activity,activity need friends union unification, fragment also need friends League statistics. The general practice is to inherit a baseactivity,basefragment.
And then in Baseactivity,basefragment, that's probably it.
Importandroid.support.v7.app.AppCompatActivity; Public classBaseactivityextendsappcompatactivity {@Overrideprotected voidOnStart () {Super. OnStart (); Mobclickagent.onpagestart (Getpagename ( This)); } @Overrideprotected voidOnStop () {Super. OnStop (); Mobclickagent.onpageend (Getpagename ( This)); }}
But if your code introduces other AAR code, they have activity in AAR, but you don't have to be someone else's code, but you need to count their activity.
Public classActivitylifecyclemonitorcallbackImplementsApplication.activitylifecyclecallbacks {Private Static Final BooleanDEBUG =Appenv.bappdebug; Private Static FinalString TAG = DEBUG? "Activitylifecymonitor": Activitylifecymonitor.class. Getsimplename (); @Override Public voidonactivitycreated (activity activity, Bundle savedinstancestate) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "onactivitycreated activity=" +Activity.hashcode ()); }} @Override Public voidonactivitystarted (activity activity) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "onactivitystarted"); } mobclickagent.onpagestart (Getpagename (activity)); } @Override Public voidonactivityresumed (activity activity) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "Onactivityresumed"); } mobclickagent.onresume (activity); } @Override Public voidonactivitypaused (activity activity) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "onactivitypaused"); } mobclickagent.onpause (activity); } @Override Public voidonactivitystopped (activity activity) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "onactivitystopped"); } mobclickagent.onpageend (Getpagename (activity)); } @Override Public voidonactivitysaveinstancestate (activity activity, Bundle outstate) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "Onactivitysaveinstancestate"); }} @Override Public voidonactivitydestroyed (activity activity) {if(DEBUG) {log.i (TAG, Getpagename (activity)+ "onactivitydestroyed activity=" +Activity.hashcode ()); } } PrivateString Getpagename (activity activity) {returnActivity.getclass (). GetName (); }}
and register it in application.
Private void registeractivitylifecyclecallback (Application application) { activitylifecyclemonitorcallback New Activitylifecyclemonitorcallback (); Application.registeractivitylifecyclecallbacks (Activitylifecyclemonitor); }
Application of the official Android Architecture component Introduction (iv)