# Learning Diary 4
###### tags: `fh` `MAD`
## Lifecycle
Please watch Lesson 4 of the Udacity Course "Developing Android Apps with Kotlin" and implement the example App from the course. Answer the following questions and submit this document as your learning diary 4.
Udacity Course "Developing Android Apps with Kotlin", Lesson 4 (1/2)
## 1. Explain the lifecycle methods of Activities in Android and give for each method an example situation when this method is called (e.g. which method is called when you use an app and a phone call comes in or when you open a “share with” dialog window).
(2 point)
The following are the lifecycle methods and a brief explanation:
* **onCreate**: handles one time initializations and layout inflations. Exclusively called when starting the application.
* **onStart**: Starts objects that only run when the activity is visible on screen.
* **onResume**: Stop objects that only run when the activity is visible on the screen. Reloads saved data.
* **onPause**: Blocks UI from drawing. This should be keept light-weight
* **onStop**: Frees up UI for drawing. Might save data.
* **onDestroy**: Final tear down of the app to free up resources
* **onRestart**: a lot like onCreate but is called when app was already created before and just pushed to the background.
## 2. Start with the starter code for Dessert Pusher App and implement Lifecycle methods as instructed in the course. Please reflect on your main insights, learnings and problems when implementing the Dessert Pusher App from the course (500-1.000 words), in particular reflect on Lifecycle Observer and onSaveInstanceState. Include 4-7 screenshots.
(3 points)
### Exercise 1: intro to logging
Every activity and every fragment has a lifecyle.
ZB activity: Initialized -> Created -> Started -> Resumed -> Destroyed.
Mostly track if acitivty is on screen or user has navigated away.
Being a good andoid citizen -> apps im hintergrund sollen keine Resourcen fressen.


If i interpreted the given Informations correctly the log level in the exercise with "i" means "Info" which shows the expected log messages as well as warnings errors and asserts.

For some reason my own override did not work enenthou it should (its almost the same as in the example solution).

### Exercise 2: application class & timber
* helps generate tags
* avoid logs in released app apks
* easy integration with crash reporting
To integrate it:
* Add Timber to build.gradle

* **make application class**: contains global application states for the entire app, also main object that main OS uses to interact with the app

* **add application class to manifest**

Nachdem noch nichts mit Timber gemacht wurde initialisiert man es erstmal. Projekt clean laden hilft falls Timber nicht erkannt wird trotz import.

* **initialize timber in application class**
This time around both logs were displayed.

### Exercise 3: reding logs/lifecycle methods
To make my life easier is wrote custom logs for every function that is asked to inspect so i would have it easier to spot them.
I later found out that i was supposed to do that.


### Exercise 4: avoiding lifecycle memory leaks

### Exercise 5: lifecycle observation
uses observer-pattern to take responsibilities off of the MainActivity.
The lifecycle is a kotlin object, representing another lifecycle like the activity Lifecycle.

### Exercise 6: process shutdown demo
i had trouble recreating this since i couldnt edit the path in the
### Exercise 7: onSaveInstanceState
the tricky part here was the timer but with a bit of tinkering around i got it:



## Open Questions (2/2)
Please list any open questions.