`Day18` - Finish lesson 4 ◦ Activity Life Cycl...
# 100daysofkotlin-2021
j
Day18
• Finish lesson 4 ◦ Activity Life Cycle ▪︎ onCreate - one time initializations, layout inflations /_onDestroy_ - destroy everything ▪︎ onStart - start objects that only run when activity is on screen / onRestart - anything that runs only if not being created / onStop - stop objects that only run when activity is on screen. permanently save data ▪︎ onPause - called when activity loses focus / onResume - called when activity gains focus ◦ Fragment Life Cycle (states are the same, but the callbacks are different) ▪︎ onCreate / onCreateView / onStop / onAttach / onActivityCreated / onStart / onResume / onDestroyView / onDestroy / onDetach - be aware of fragment specific cautions.. (ex. should inflate layout xmls in onCreateView not in onCreate) ◦ Using LifecycleObserver ◦ Process shutdown (Android OS takes the state of some of your views and saves them to a bundle, to RAM when you navigate away.) ▪︎ onSaveInstanceState - safely save in case app process is torn down by OS. • Should call super method to automatically save basic informations such as backstack info & some data values. • To manually add data to bundle, call putXX methods with key and value. Key must be string. • size of bundle is restricted, varies by device ◦ Configuration changes causes the activity to be rebuilt ▪︎ example of config change - user changes device language, plugs in physical device, rotates device
Self-Comment
• It’s quite amazing when design pattern I’ve learned in class(but just went through my ear..) appear again. Good to see u observer pattern. • Managing life cycles seems to be important. For all this time I just used onCreate for initialization, without knowing anything about all these.🙄
Goals Tomorrow
• Halfway to lesson 5 & googling for android ble
🔥 1