For the purpose of profiling, I instrumented my android application so that it collects some log at the beginnings and ends of all functions. I do so by calling a public static method called keepLog(String log)
at method boundaries. I also wrote another public static method called writeCollectedLogs()
which is supposed to write all collected logs into disk. It is important that all logs are written at once because I do not want to use write system-call every time (instead I prefer to keep logs in memory and write everything on disk only once at the end)
My problem is I do not know where to call writeCollectedLogs()
. I am looking for some onTerminate()
method for the whole android app. However, non of android default onDestroy
and onTerminate()
seems to work in my case. It is important to note that I have 2 methods of running my application. Sometimes I run my app using android instrumentation test runner and sometimes I use adb to start activities and send touch events manually.
Instrumentation test runner opens my app, runs the tests and then closes the app. In the second scenario however, I have control over my app life cycle. I am looking for a universal way of calling for writeCollectedLogs
just before the app closes.
Any suggestions?