1. Are you ready for the Galaxy S20? Here is everything we know so far!

Architectural question: Android Studio Navigation Drawer template project files

Discussion in 'Android Development' started by purplebeans, Apr 24, 2020.

  1. purplebeans

    purplebeans Lurker
    Thread Starter

    My question is an architectural question about Android Studio's Navigation Drawer template project files.
    I am teaching myself to use Android for an app for my final year BSc computing project with the Open University (UK).

    1) Why does the Navigation Drawer template project include both ViewModel java files for each of the Fragments as well as fragment java files?

    I'm trying to understand if this is the way Fragments are usually structured with a separate java file for the actual content of a Fragment screen. If this is the case, what would I put in the Fragment java file rather than the ViewModel java file?

    2) The template also provides a second home Fragment, I'm really not sure why? Any explanation for that? (I don't think I need this...)

    3) As I'm completely new to Android Fragments (I think I understand how to work with just Activities), could someone please explain the role of the single Activity in the the Navigation Drawer template project?

    I understand that you need an Activity to underpin the Fragments. Does the Activity actually need to be one of the visible screen like the home screen (as it would be in an app without Fragments) or is it just there behind the scenes providing the functionality for the Fragments according to what java code I put in the Fragments and Activity java files?

    These things are puzzling me.

    So far I have adapted the Navigation Drawer template so that there is just the one MainActivity.java file with 5 Fragments, each with a unique Fragment.java and ViewModel.java file and a layout.xml file per Fragment. The home screen is one of the Fragments and the Activity is not visible. Is this a good structure?

    Any explanations or feedback would be very gratefully received, thanks from purplebeans!

    1. Download the Forums for Android™ app!



Share This Page