Android Flashcards
OOP Concepts.
Object-Oriented Programming is a methodology of designing a program using classes, objects, inheritance, polymorphism, abstraction, and encapsulation
Inheritance
defined as deriving new classes (sub classes) from existing ones (super class or base class) and forming them into a hierarchy of classes.an object created through inheritance (a “child object”) acquires all the properties and behaviors of the parent object (except: constructors, destructor, overloaded operators and friend functions of the base class)
polymorphism
the use of a single symbol to represent multiple different types.
Abstraction
only the general states and behaviors are taken and more specific states and behaviors are left aside for the implementers
Encapsulation
Encapsulation is an OOPS concept to create and define the permissions and restrictions of an object and its member variables and methods
constructor
A constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation. Constructor Name should be same as class name. A constructor must have no return type.
destructor
A destructor is a method which is automatically called when the object is made of scope or destroyed. Destructor name is also same as class name but with the tilde symbol before the name.
Function overloading
Function overloading an as a normal function, but it can perform different tasks. It allows the creation of several methods with the same name which differ from each other by the type of input and output of the function.
types of arguments
Call by Value – Value passed will get modified only inside the function, and it returns the same value whatever it is passed it into the function.
Call by Reference – Value passed will get modified in both inside and outside the functions and it returns the same or different value.
ternary operator
?: is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages.
super
a reference variable which is used to refer immediate parent class object,method or constructor
interface
It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
Difference between overloading and overriding
Overloading is nothing but the same method with different arguments, and it may or may not return the same value in the same class itself.
Overriding is the same method names with same arguments and return types associated with the class and its child class.
THIS
THIS pointer refers to the current object of a class. THIS keyword is used as a pointer which differentiates between the current object with the global object
Static polymorphism and Dynamic polymorphism
Static polymorphism in Java is achieved by method overloading
Dynamic polymorphism in Java is achieved by method overriding
android spp components
An activity represents a single screen with a user interface,in-short Activity performs actions on the screen
A service is a component that runs in the background to perform long-running operations.
Broadcast Receivers simply respond to broadcast messages from other applications or from the system.
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class
context
An Android Context is an Interface (in the general sense, not in the Java sense; in Java, Context is actually an abstract class!) that allows access to application specific resources and class and information about application environment.
AndroidManifest.xml
The AndroidManifest.xml file contains information of your package, including components of the application
Application class
The Application class in Android is the base class within an Android app that contains all other components such as activities and services
diff activity and fragments
Activity is an application component which give user interface where user can interect. Fragment is a part of an activity,which contibute its own UI to that activity.
Activity is not dependent on fragment.but Fragment is dependent on Activity,it can’t exist independentaly.
Communicate with other fragments
getSupportFragmentManager().findFragmentById(R.id.article_fragment);
View
View objects are the basic building blocks of User Interface(UI) elements in Android.
View is a simple rectangle box which responds to the user’s actions.
Examples are EditText, Button, CheckBox etc..
View refers to the android.view.View class, which is the base class of all UI classes.
ViewGroup
ViewGroup is the invisible container. It holds View and ViewGroup
For example, LinearLayout is the ViewGroup that contains Button(View), and other Layouts also.
ViewGroup is the base class for Layouts
custom view
For drawing view use the onDraw() method. In this method you receive a Canvas object which allows you to perform drawing operations on it
SurfaceView
Provides a dedicated drawing surface embedded inside of a view hierarchy.
layout types
LinearLayout means you can align views one by one (vertically/ horizontally).
RelativeLayout means based on relation of views from its parents and other views.
ConstraintLayout is similar to a RelativeLayout in that it uses relations to position and size widgets, but has additional flexibility and is easier to use in the Layout Editor.
WebView to load html, static or dynamic pages.
FrameLayout to load child one above another, like cards inside a frame, we can place one above another or anywhere inside the frame.
deprecated - AbsoluteLayout means you have to give exact position where the view should be.
Table Layout: A layout that arranges its children into rows and columns
List View
Pros:
simple usage default adapters available OnItemClickListener it’s the foundation of the ExpandableListView Cons:
doesn’t embrace the usage of the ViewHolder pattern
Recycle View
Pros:
integrated animations for adding, updating and removing items
enforces the recycling of views by using the ViewHolder pattern
supports both grids and lists
supports vertical and horizontal scrolling
can be used together with DiffUtil
Cons:
adds complexity
no OnItemClickListener
view holder
ViewHolder pattern is solely to reduce the number of view.findViewById(int) calls you make.
intent
An Intent is a messaging object you can use to request an action from another app component.
intent types
Explicit intents specify which application will satisfy the intent, by supplying either the target app's package name or a fully-qualified component class name. You'll typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start. For example, you might start a new activity within your app in response to a user action, or start a service to download a file in the background. Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map, you can use an implicit intent to request that another capable app show a specified location on a map.
intent filter
An intent filter is an expression in an app’s manifest file that specifies the type of intents that the component would like to receive.
Sticky Intent
Sticky Intent is also a type of Intent which allows a communication between function and a service sendStickyBroadcast() performs a sendBroadcast(Inent) know as sticky,the Intent your are sending stays around after the broadcast is complete,
PendingIntent
By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself
job scheduler
The JobScheduler API allows you to specify robust conditions for executing tasks, along with centralized task
diff service and intent service
A Service is an application component representing either an application’s desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
IntentService, which is a direct subclass of Service is borned to make things easier. The IntentService is used to perform a certain task in the background. Once done, the instance of IntentService terminate itself automatically.