java - Android event logging -


i looking ward log events fired inside activity such onclick, edittextchanged, ontouch without effort programmer providing him library. there ways of doing without requiring him put annotations inside event handlers? example can create super activity , tell him extend it. thanks.

i got idea mobile cloud computing class @ coursera. every activity in sample code provided class extended this:

/**  * abstract class extends activity class , overrides lifecycle  * callbacks logging various lifecycle events.  */ public abstract class lifecycleloggingactivity extends activity { /**  * debugging tag used android logger.  */ protected final string tag = getclass().getsimplename();  /**  * hook method called when new instance of activity created. 1 time  * initialization code should go here e.g. ui layout, class scope  * variable initialization. if finish() called oncreate no other  * lifecycle callbacks called except ondestroy().  *   * @param savedinstancestate  *            object contains saved state information.  */ @override protected void oncreate(bundle savedinstancestate) {     // call super class necessary     // initialization/implementation.     super.oncreate(savedinstancestate);      if (savedinstancestate != null) {         // activity being re-created. use         // savedinstancestate bundle initializations either         // during oncreate or onrestoreinstancestate().         log.d(tag, "oncreate(): activity re-created");      } else {         // activity being created anew. no prior saved         // instance state information available in bundle object.         log.d(tag, "oncreate(): activity created anew");     }  }  /**  * hook method called after oncreate() or after onrestart() (when  * activity being restarted stopped state). should re-acquire  * resources relinquished when activity stopped (onstop()) or acquire  * resources first time after oncreate().  */ @override protected void onstart() {     // call super class necessary     // initialization/implementation.     super.onstart();     log.d(tag, "onstart() - activity become visible"); }  /**  * hook method called after onrestorestateinstance(bundle) if there  * prior saved instance state in bundle object. onresume() called  * after onstart(). onresume() called when user resumes  * activity paused state (onpause()) user can begin interacting  * activity. place start animations, acquire exclusive resources, such  * camera.  */ @override protected void onresume() {     // call super class necessary     // initialization/implementation , log lifecycle     // hook method being called.     super.onresume();     log.d(tag,             "onresume() - activity has become visible (it \"resumed\")"); }  /**  * hook method called when activity loses focus still visible in  * background. may followed onstop() or onresume(). delegate more cpu  * intensive operation onstop seamless transition next activity.  * save persistent state (onsaveinstancestate()) in case app killed.  * used release exclusive resources.  */ @override protected void onpause() {     // call super class necessary     // initialization/implementation , log lifecycle     // hook method being called.     super.onpause();     log.d(tag,             "onpause() - activity taking focus (this activity \"paused\")"); }  /**  * called when activity no longer visible. release resources may  * cause memory leak. save instance state (onsaveinstancestate()) in case  * activity killed.  */ @override protected void onstop() {     // call super class necessary     // initialization/implementation , log lifecycle     // hook method being called.     super.onstop();     log.d(tag,             "onstop() - activity no longer visible (it \"stopped\")"); }  /**  * hook method called when user restarts stopped activity. followed  * call onstart() , onresume().  */ @override protected void onrestart() {     // call super class necessary     // initialization/implementation , log lifecycle     // hook method being called.     super.onrestart();     log.d(tag, "onrestart() - activity restarted()"); }  /**  * hook method gives final chance release resources , stop  * spawned threads. ondestroy() may not called-when system kills  * hosting process  */ @override protected void ondestroy() {     // call super class necessary     // initialization/implementation , log lifecycle     // hook method being called.     super.ondestroy();     log.d(tag, "ondestroy() - activity destroyed"); }  } 

it developed vanderbilt university course , part of framework simplifying activities. don't have license hand, use it, not claim in way app or code endorsed vanderbilt university or coursera.

every activity extends 1 automatically log of lifecycle methods, tagged class name.

edit

to methods interfaces, mentioned, need create implementation of interface follows same idea, , use variable in activity instead of directly implementing interface in activity.


Comments