I am trying to minimize the number of places in my code where I need to install StrictMode. But I'm not sure whether I am right or not about the following.
The Android StrictMode documentation says you can use it for apps, activities, and other components. I read that it is not advisable to extend the Application class, and I would prefer not to extend the application to enable StrictMode. But I donโt think I should.
There are two policies you can use: ThreadPolicy (for thread) and VmPolicy (for all threads). Thus, it would seem that if I install StrictMode on a thread once, it doesnโt matter where I do it from, and after that violations will be reported in this thread regardless of other calls or not on StrictMode. I just need to call him from somewhere before the disturbances that I want to detect can occur. And it must be configured for any new threads that are created in my application that I also want to check.
What I think I want to avoid calls the build () methods more than I need. Putting StrictMode at the beginning of onCreate() in all my actions means that the build () function will be called more than once in this thread. If I have one Launcher activity in my application, setting StrictMode in this onCreate() action should be sufficient for the rest of the application. It's true?
Secondly, if my main action restarts, although the application has not died, is it technically necessary to call StrictMode again? Or is my thread still configured to report abuse? I thought there might be some value in creating a wrapper type class around StrictMode, for example:
public class MyStrictModeSettings { static private List<Long> setThreads = new ArrayList<Long>();
Thus, in my main onCreate () action, I can just call MyStrictModeSettings.init () and do with it. And it should work with Android versions up to 2.3. But it may not be worth it. Brad, are you there? Thanks.
Edit: Since VmPolicy is designed for all threads, technically I only need to install it once for the application, right? So enableDefaults () wastes efforts on repeating VmPolicy when it is called second, third, etc. Time? Again, maybe this is more of a problem than trying to avoid extra calls.