Apps and APK Files
An Android app is an Android Application. An app is packaged in an APK file i.e. Android application package. The APK file contains the compiled Java code and other resources like images and texts for the Android application
An Android activity is a GUI component. You can understand it as a window in a desktop application. As mobile phone screens are small, an activity takes up the whole screen. If you open multiple activities then they are stacked on top of each other. You cannot arrange activities side by side like you can do with desktop windows.
Activities are unique, focused actions which a user can take. As it is difficult to scroll, zoom in or click links on a small screen hence it is recommended that an app display only one activity per screen. This will present the most relevant information to the user and allows them to launch a new screen for additional information or click the back button to view the previous activity. The screen can expose multiple tasks but it should help the user complete just one activity at a time.
In Android, a fragment is a fragment of a total user interface. A fragment only takes up part of the screen. Fragments are used in the activities. Fragments can also be used within different activities. Fragments contain Views and ViewGroups inside them.
View and ViewGroups
Android GUI elements come into three categories i.e. Activities, Views and ViewGroups. Activities are the windows/screens. Views are the individual GUI elements, like a TextView which displays a text, a Button that users can click on etc. ViewGroups are containers for Views. A ViewGroup actually groups a collection of Views together. Views and ViewGroups can be nested inside an activity or inside even a fragment which is nested inside an activity.
Layout XML Files
Activities, fragments and ViewGroups can use XML files to define their layout and contents. The layout XML files tell which GUI components an activity or fragment contains and also the styling of the GUI components i.e. The size, margins, padding etc.
If your app requires performing a function beyond its core capabilities like opening a photo, playing a video or looking up a contact then you should find out whether a tool that can perform that function already exists in the OS or in a third-party app. If yes then you can get the benefit of that functionality using intents.
For e.g. If your app accesses user contacts then you can use intent objects to launch the device’s existing Contacts application. This removes the programming duplication and also speed up the user’s interaction with the device as the user will not need to learn again how to add a contact to your app.
Android Widgets are actually GUI components which can be displayed outside of an activity. For e.g. A weather widget which shows today’s weather is shown on many Android home screens. Widgets have been packaged and implemented as part of an Android application. Also sometimes Views in Android are also referred to as widgets. For e.g. Many GUI components are placed in a Java package called android.widget. GUI components are not same as a widget which can remain on the home screen of an Android device. Hence you should understand the difference between GUI components which can be used inside ViewGroups, Fragments and components which can be used inside ViewGroups, Fragments and Activities and also inside Widgets and Widgets which can remain on the home screen of the Android device.