I have a helper class that should only ever run in a background thread. Is there a way I can leverage the StrictMode component and throw my own StrictMode violation if it’s run on the main thread?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As of API 11, it looks like the best option is to use a ThreadPolicy.Builder to detectCustomSlowCalls(). In the background thread, you can then tag the method as ‘slow’ by calling StrictMode.noteSlowCall().
This apparently means that a StrictMode violation will be thrown if the offending method takes too long to execute.