Day56 of #100DaysOfCode

#CodeTogether Day 56/100

Hii folks 🙌

Today I will be continuing the same pathway in which I will build the Dessert Clicker app.

Unit 3: Navigation

Pathway 2: Introduction to the Navigation component

Source: https://developer.android.com/courses/android-basics-kotlin/course

Fragments and the Navigation Component

We will start by downloading the repo from the given link in the course and setting it up in Android Studio.

A fragment is simply a reusable piece of our app’s user interface. The fragment's lifecycle state will be as follows:

  • INITIALIZED: A new instance of the fragment has been instantiated.
  • CREATED: The first fragment lifecycle methods are called. During this state, the view associated with the fragment is also created.
  • STARTED: The fragment is visible onscreen but does not have “focus”, meaning it can’t respond to user input.
  • RESUMED: The fragment is visible and has focus.
  • DESTROYED: The fragment object has been de-instantiated.

Similar to activities, the Fragment class provides many methods that we can override to respond to lifecycle events.

  • onCreate(): The fragment has been instantiated and is in the CREATED state. However, its corresponding view has not been created yet.
  • onCreateView(): This method is where we inflate the layout. The fragment has entered the CREATED state.
  • onViewCreated(): This is called after the view is created. In this method, we would typically bind specific views to properties by calling findViewById().
  • onStart(): The fragment has entered the STARTED state.
  • onResume(): The fragment has entered the RESUMED state and now has focus (can respond to user input).
  • onPause(): The fragment has re-entered the STARTED state. The UI is visible to the user
  • onStop(): The fragment has re-entered the CREATED state. The object is instantiated but is no longer presented on screen.
  • onDestroyView(): Called right before the fragment enters the DESTROYED state. The view has already been removed from memory, but the fragment object still exists.
  • onDestroy(): The fragment enters the DESTROYED state.

The lifecycle states and callback methods are quite similar to those used for activities. However, the difference with the onCreate() method. With activities, we would use this method to inflate the layout and bind views. However, the fragment lifecycle onCreate() is called before the view is created, so we can't inflate the layout here. Instead, we do this in onCreateView(). Then, after the view has been created, the onViewCreated() method is called, where we can then bind properties to specific views.

That is all for Day56 ✅

Thanks for reading, See you tomorrow!

If you are reading my #100Days Journey, feel free to drop by ;)

--

--

--

https://www.linkedin.com/in/itskushagra

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Integrate Social Media with Android app: Facebook 1/3

Mobile

A much better approach to managing our repository with MVVM in android

Setup Flutter: IDE Configuration — Android

Right way to add vertical divider in Flutter

Kotlin — ‘for’ loop in 2 min (Updated - Jun, 2020)

Retrying failed network requests automatically on Android

Why use RxDart and how we can use with BLoC Pattern in Flutter?

Dots Indicator for Viewpager made easy — Android

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kushagra Kesav

Kushagra Kesav

https://www.linkedin.com/in/itskushagra

More from Medium

Day68 of #100DaysOfCode

Day97 of #100DaysOfCode

Day60 of #100DaysOfCode

Day71 of #100DaysOfCode