Comments (7)
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.
Why are you using StrictMode?
from colorful.
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.
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.
Colorful code uses SharedPreferences disk read operation, running all I/O as non-blocking off the main thread is ideal.
from colorful.
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.
Thanks for reply, I understand.
from colorful.
Related Issues (20)
- Not working after app restart HOT 4
- Use custom color HOT 11
- Load style resources by name not by id
- "setPrimaryColor" and "setCustomThemeOverride" conflict HOT 12
- Disabled override how to use light/dark theme HOT 1
- Request to add color HOT 3
- Use THEME_MATERIAL appear error log HOT 10
- Some times primaryColor and accentColor are not used HOT 9
- Sample code for use without kotlin HOT 5
- Compile issue error: style attribute 'attr/colorSecondary HOT 11
- Does Proguard settings mentioned in document?
- Material Drawer Theming Support? HOT 3
- Migrate to AndroidX HOT 1
- How to customize views in theme?
- ThemeEditor public apply method needs null check
- startSupportActionMode works not propertly with Colorful
- ERROR: Failed to resolve: com.github.garretyoder:Colorful:2.3.4 HOT 1
- R styles not found on API 19 HOT 1
- App bar and Statusbar need same color HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colorful.