CWAC StrictModeEx: Punishment for the Bad Code In Your App
StrictMode is a handy feature in API Level 9 and higher,
telling you where your Android application is doing things
it probably should not on the main application thread.
In the spirit of
offers classes to help you diagnose similar sorts of problems
StrictMode itself offers.
Right now, that consists of one class:
ListAdapter wrapper will log slow-running
plus optionally give you an overall performance view on how
Adapter is doing in the code you control.
This is available as a JAR file. The project itself is set up as an Android library project, in case you wish to use the source code in that fashion.
Normally, you create your own
ListAdapter (e.g., an
and give that to your
setListAdapter() on a
Now, you create your own
ListAdapter, wrap it in a
and put the
StrictAdapter in the
AdapterView. To do this, just
StrictAdapter constructor, which takes your regular
ListAdapter as a parameter.
By default, the
StrictAdapter will log all calls to
that take longer than 1ms (1000000ns). You can alter this by
setThreshold(), which takes the desired threshold
time in nanoseconds.
getView() call that takes longer than the threshold is logged
with error severity to LogCat. By default, the tag will be
though you can change this via a call to
If you want, you can dump the overall performance metrics to LogCat
(debug severity) via a call to
dumpResultsToLog(). This will report
the total number of
getView() calls, the number that were penalized
(i.e., exceeded the threshold), the total time across all the calls,
and the mean time per call. A call to
reset() clears the statistics.
Even on production hardware with a trivial
ListAdapter (such as the
one in the
demo/ sub-project), you will find
getView() calls that
exceed the default 1ms threshold. It should only be a few percent of
the total number of calls, and it could easily represent background
work from other processes that happened to steal a time slice while
getView() was running.
This project relies upon the [CWAC AdapterWrapper][adapter] project.
A copy of compatible JARs can be found in the
of the project, though you are welcome to try newer ones, or
ones that you have patched yourself.
This project should work on API Level 7 and higher, except for any portions that may be noted otherwise in this document. Please report bugs if you find features that do not work on API Level 7 and are not noted as requiring a higher version.
This is version v0.1 of this module, meaning it is brand-spankin' new.
demo/ sub-project you will find
a sample activity that demonstrates the use of
The code in this project is licensed under the Apache Software License 2.0, per the terms of the included LICENSE file.
If you have questions regarding the use of this code, please post a question
on StackOverflow tagged with
android. Be sure to indicate
what CWAC module you are having issues with, and be sure to include source code
and stack traces if you are encountering crashes.
If you have encountered what is clearly a bug, or a feature request, please post an issue. Be certain to include complete steps for reproducing the issue.
Do not ask for help via Twitter.
Also, if you plan on hacking on the code with an eye for contributing something back, please open an issue that we can use for discussing implementation details. Just lobbing a pull request over the fence may work, but it may not.
Who Made This?
- v0.1.0: initial release