简体   繁体   中英

Where to place StrictMode code within an Android app

here is my situation:

Have am developing an Android app with 5 Activities:

  1. SplashActivity
  2. MainActivity
  3. ActivityA
  4. ActivityB
  5. ActivityC

The app starts with the splash screen, then displays the main activity. From there the user can select activity A,B or C.

I wanted to test the entire app with StrictMode, both thread and VM policies. I know that for an app with only one activity, the code for both policies would go at the top of onCreate() in that one activity. There are many examples of this on the 'net, but none with more than one activity.

I am thinking for my particular situation, both the VM and thread policies would go at the top of onCreate() in the SplashActivity, since that is the very beginning of the app. I am thinking this would cover the VM policy for the entire app.

In addition, the thread policy would go at the top on onCreate() in each of the remaining activities, in order to detect problems in any of them.

My question here is: Is this the proper way to go about testing with StrictMode? If not, what is the best way to go about it?

If you would like to apply the policy to the whole app then you need to do it when your app is initialized. Subclass Application and overrride YouApplication.onCreate() and set you policy here. Dont forget to define in your manifest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM