Android — Application Class vs. SharedPreferences
Share your data globally. Which one to use?
I’ve update my apps to include OneSignal Push Notif. Came across its documentation here:
OneSignal is a Push Notification service for Web Push, iOS, Android, Chrome, Unity 3D, Amazon, Windows Phone, Phonegap…documentation.onesignal.com
Why the init is extending Application class?
This article also, explained why we should.
We know there is an Application class in the Android api and according to the class name, it's used for global settings…www.mobomo.com
Okay, so what’s the difference with SharedPreferences?
After researching, I found a useful answer here:
- Recommendation use of SharedPref: http://stackoverflow.com/a/11567825/3763032
- Why you shouldn’t use Application Class: http://stackoverflow.com/a/10817853/3763032
- When to use both: http://stackoverflow.com/a/14186583/3763032
- TL;DR, how Application Class works: https://guides.codepath.com/android/Understanding-the-Android-Application-Class
There’s no right answer really, use it to suit your needs :D but thanks for visiting!
OneSignal is relatively simple to configure. You might want to check its documentation here
Also, you might wanna check my previous article on how to maintain your data state when NavigationUp cycles here
Happy coding, guys!!!