Application of the official Android Architecture component Introduction (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.