GithubHelp home page GithubHelp logo

Comments (7)

tcqq avatar tcqq commented on August 30, 2024

I fixed the above error log in this way.

abstract class BaseApp : Application(), Application.ActivityLifecycleCallbacks {

    override fun onCreate() {
        if (BuildConfig.DEBUG) {
            setStrictMode()
        }
        super.onCreate()

        registerActivityLifecycleCallbacks(this)

            Thread {
                val defaults = Defaults(
                        primaryColor(),
                        accentColor(),
                        isDark(),
                        isTranslucent(),
                        customTheme())
                initColorful(this, defaults)
            }.start()

    override fun onActivityCreated(activity: Activity, bundle: Bundle?) {
            AppCompatDelegate.setDefaultNightMode(if (Colorful().getDarkTheme())
                AppCompatDelegate.MODE_NIGHT_YES
            else
                AppCompatDelegate.MODE_NIGHT_NO)
        }
}

from colorful.

garretyoder avatar garretyoder commented on August 30, 2024

Why are you using StrictMode?

from colorful.

tcqq avatar tcqq commented on August 30, 2024

Best practice in Android says “keeping the disk and network operations off from the main thread makes applications much smoother and more responsive”. StrictMode which detects things you might be doing by accident and brings them to your attention so you can fix them.

from colorful.

garretyoder avatar garretyoder commented on August 30, 2024

StrictMode is infamous for miss flagging things. If you look at the error, the specific line of Colorful's code it's flagging is the following.

var primary: ThemeColorInterface = ThemeColorInterface.parse(prefs.getString(primaryThemeKey, defaults.primaryColor.themeName))

This is just a simple shared preference read. SharedPreferences is already correctly managed by the android system. This is not a bug in colorful and a nonissue, closing.

from colorful.

tcqq avatar tcqq commented on August 30, 2024

Colorful code uses SharedPreferences disk read operation, running all I/O as non-blocking off the main thread is ideal.

from colorful.

garretyoder avatar garretyoder commented on August 30, 2024

You're welcome to submit a PR to change the data read source to somewhere else, however as I said, strict mode isn't really a good thing to use in production. As soon as you get different devices that perform operations at different speeds, you end up triggering strict mode on some devices but others are fine. Strict mode is meant to encourage good practices. Did you see the time the message gave you? 25ms. That's a very insignificant amount of time for a load, hell it takes Android longer to create a Theme object, but that's ignored by strict mode.

If it irks you that much submit a PR, but I'm considering this a non-issue because this won't affect performance in the slightest or block a thread for any meaningful amount of time.

Hell, calling super.onCreate in a activity is a longer running operation than that.

from colorful.

tcqq avatar tcqq commented on August 30, 2024

Thanks for reply, I understand.

from colorful.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.