Welcome to my Android Development Basics repository! This repository contains the code and resources for various practical exercises and projects related to Android development. These exercises cover fundamental concepts and topics in Android app development using Java.
This repository serves as a collection of practical exercises and projects completed as part of my journey in learning Android development basics. Each folder contains a separate project or exercise focusing on specific topics.
The exercises and projects in this repository cover a wide range of Android development topics, including but not limited to:
- User Interface (UI) Development
- Data Storage and Persistence
- Networking and Web Services
- Background Processing
- Permissions and Security
- Location and Maps
- Notifications
- Sensors and Device Interaction
- Multimedia
- Android Jetpack Components
- Firebase Integration
- Testing and Debugging
- App Deployment and Distribution
- Advanced Topics
The repository is organized into folders based on the topics covered. Each folder contains a separate project or exercise along with relevant resources and documentation.
Here's the updated folder structure:
UI_Development
: Projects related to UI development.Data_Storage
: Projects related to data storage and persistence.Networking
: Projects related to networking and web services.Background_Processing
: Projects related to background processing.Permissions_Security
: Projects related to permissions and security.Location_and_Maps
: Projects related to location-based services and maps.Notifications
: Projects related to notifications.Sensors_Device_Interaction
: Projects related to sensors and device interaction.Multimedia
: Projects related to multimedia (audio, video).Jetpack_Components
: Projects related to Android Jetpack components.Firebase_Integration
: Projects related to Firebase integration.Testing_Debugging
: Projects related to testing and debugging.App_Deployment
: Projects related to app deployment and distribution.Advanced_Topics
: Projects covering advanced Android development topics.
To use the projects and exercises in this repository:
- Clone or download the repository to your local machine.
- Open the desired project folder in Android Studio.
- Review the project structure, source code, and any accompanying documentation.
- Run the project on an emulator or physical device to see it in action.
- Explore and experiment with the code to deepen your understanding of Android development concepts.
Contributions to this repository are welcome! If you'd like to contribute an exercise, project, or improvement, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-branch-name
). - Make your changes and commit them (
git commit -am 'Add new exercise'
). - Push your changes to your forked repository (
git push origin feature/your-branch-name
). - Create a new Pull Request.
- Common Coding Programs
- Data Structure Coding Programs
- Android Interview Questions
- Java Interview Questions
-
Arrays
- Find Maximum Sell Profit
- Find Low & High Index of a key from a given array
- Merge Overlapping Intervals
- Move all zeros in an array to the Left or Right
- Rotate an array
- Find the smallest common number in a given array
- Find the sum of two elements in a given array
- Find the minimum distance between two numbers in an array
- Find the maximum difference between the values in an array such that the largest values always comes after the smallest value
- Find second largest element in an array
- Find the 3 numbers in an array that produce the max product
- Find missing number from an array
-
Dynamic Programming
- Fibonacci Series
- Given an array, find the contiguous subarray with the largest sum
- Find the maximum sum of a subsequence such that no consecutive elements are part of the subsequence
- Given a score "n", find the total number of ways score "n" can be reached
- Compute Levenshtein distance between two strings
- Given coin denominations and the total amount, find out the number of ways to make the change
-
Queues
-
LinkedList
- Reverse a Linked List
- Remove duplicates from a Linked List
- Delete Node of a given key from a Linked List
- Find the Middle Node of a Linked List
- Find the Nth Node of a Linked List
- Check if a Linked List is cyclic
- Insertion Sort of a Linked List
- Intersection Point of Two Lists
- Nth from last node
- Swap Nth Node with Head
- Merge Two Sorted Linked Lists
- Sorting LinkedList using merge sort
- Reverse nodes at even indices
- Rotate linked list by n
- Reverse every 'k' elements in a linked list
- Add the head pointers of two linked lists
-
Stacks
- Evaluate an expression
- Implement a stack using queues
- Check if paranthesis are equal
- Tower of Hanoi
- ReverseAStack
-
Back Tracking
- Solve Boggle
- Print paranthesis combination for a given value
- Solve N queen problem
- find all the subsets of the given array that sum up to the number K
-
Graphs
-
Trees
- Implements an InOrder Iterator on a Binary Tree
- Convert a binary tree to a doubly linked list
- Connect a sibling pointer of a binary tree to next node in the same level
- Given a binary tree, connect its siblings at each level
- Delete any subtrees whose nodes sum up to zero
- Given roots of two binary trees, determine if these trees are identical
- Find the Inorder successor of a node in binary Search Tree
- Algorithm to traverse the tree inorder
- Check if a given tree is a binary search tree
- Display node values at each level in a binary tree
- Swap the 'left' and 'right' children for each node in a binary tree
- Find nth highest node in a Binary Search Tree
- Print nodes forming the boundary of a Binary Search Tree
- Serialize binary tree to a file and then deserialize back to tree
-
Strings
- Reverse String
- Palindrone String
- Regular Expression
- Remove Duplicates
- Remove White Spaces
- Remove a String
- String Segmentation
- Find next highest permutation of a given string
- Check if two strings are anagrams
-
Integers
- Reverse Integer
- Find sum of digits of an integer
- Find Next highest Number from a Integer
- Check if it is an Armstrong number
- Find the factorial of a number
- Print all prime numbers upto the given number
- Find all the prime factors of a given integer
- Check if a given number is binary
- Find kth permutation
- Integer Division
- Find Pythagorean Triplets
- Print all possible sum combinations using positive integers
- Find Missing Number
- Find all subsets of a given set of integers
- Given an input string, determine if it makes a valid number
- Calculate 'x' raised to the power 'n'
- Calculate square root of a number
- Minimum Number of Platforms Required for a Railway/Bus Station
-
Miscellaneous
- Find three integers in the array with sum equal to the given value
- Find position of a given key in 2D matrix
- Determine the host byte order of any system
- Find the point that requires the least total distance covered by all the people to meet at that point
- Given a two dimensional array, if any element in it is zero make its whole row and column zero
-
Sorting
- BubbleSort
- InsertionSort
- SelectionSort
- QuickSort
- MergeSort
- Question: Why is quicksort preferred over merge sort for sorting arrays?
- Quicksort does not require any extra storage whereas merge sort requires O(n) space allocation. Allocating/de-allocating memory space can increase the run time.
- Quicksort does not require any extra storage whereas merge sort requires O(n) space allocation. Allocating/de-allocating memory space can increase the run time.
- Question: Why is merge sort preferred over quicksort for sorting linked lists?
- There is a difference in linked lists due to memory allocation. In linked lists we can insert items in the middle in O(n) space and time. There is no extra memory allocation required.
- Question: Why is quicksort preferred over merge sort for sorting arrays?
-
Searching
- Binary Search
- Rotated Binary Search
- Ternary Search
- Question: Why is binary search preferred over ternary search?
- When dividing an array by k ( 2(binary) or 3(ternary)), it reduces the array size to 1/k. But it increases the no of comparisons by k.
- Question: Why is binary search preferred over ternary search?
-
What is Application?
- The Application class in Android is the base class within an Android app that contains all other components such as activities and services. The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created.
- The Application class in Android is the base class within an Android app that contains all other components such as activities and services. The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created.
-
What is Context?
- A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. An Android app has activities. Context is like a handle to the environment your application is currently running in.
Application Context: This context is tied to the lifecycle of an application. The application context can be used where you need a context whose lifecycle is separate from the current context or when you are passing a context beyond the scope of an activity.
Activity Context: This context is available in an activity. This context is tied to the lifecycle of an activity. The activity context should be used when you are passing the context in the scope of an activity or you need the context whose lifecycle is attached to the current context.
- A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. An Android app has activities. Context is like a handle to the environment your application is currently running in.
-
What is ABI Management?
- Different Android handsets use different CPUs, which in turn support different instruction sets. Each combination of CPU and instruction sets has its own Application Binary Interface, or ABI. The ABI defines, with great precision, how an application's machine code is supposed to interact with the system at runtime. You must specify an ABI for each CPU architecture you want your app to work with. You can checkout the full specifcations here
- Different Android handsets use different CPUs, which in turn support different instruction sets. Each combination of CPU and instruction sets has its own Application Binary Interface, or ABI. The ABI defines, with great precision, how an application's machine code is supposed to interact with the system at runtime. You must specify an ABI for each CPU architecture you want your app to work with. You can checkout the full specifcations here
-
Why bytecode cannot be run in Android?
- Android uses DVM (Dalvik Virtual Machine ) rather using JVM(Java Virtual Machine).
- Android uses DVM (Dalvik Virtual Machine ) rather using JVM(Java Virtual Machine).
-
What is a BuildType in Gradle? And what can you use it for?
- Build types define properties that Gradle uses when building and packaging your Android app.
- A build type defines how a module is built, for example whether ProGuard is run.
- A product flavor defines what is built, such as which resources are included in the build.
- Gradle creates a build variant for every possible combination of your project’s product flavors and build types.
-
Explain the build process in Android:
- First step involves compiling the resources folder (/res) using the aapt (android asset packaging tool) tool. These are compiled to a single class file called R.java. This is a class that just contains constants.
- Second step involves the java source code being compiled to .class files by javac, and then the class files are converted to Dalvik bytecode by the "dx" tool, which is included in the sdk 'tools'. The output is classes.dex.
- The final step involves the android apkbuilder which takes all the input and builds the apk (android packaging key) file.
-
What is the Android Application Architecture?
- Android application architecture has the following components:
a. Activities - Provides the window in which the app draws its UI
b. Services − It will perform background functionalities
c. Intent − It will perform the inter connection between activities and the data passing mechanism
d. Resource Externalization − strings and graphics
e. Notification − light,sound,icon,notification,dialog box,and toast
f. Content Providers − It will share the data between applications
- Android application architecture has the following components:
-
What is Manifest file and R.java file in Android?
- Manifest: Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code. It contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.
- R.Java: It is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory.
-
Describe activities
- Activities are basically containers or windows to the user interface.
- Activities are basically containers or windows to the user interface.
-
Lifecycle of an Activity
OnCreate()
: This is when the view is first created. This is normally where we create views, get data from bundles etc.OnStart()
: Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.OnResume()
: Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it.OnPause()
: Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed.OnStop()
: Called when you are no longer visible to the user.OnDestroy()
: Called when the activity is finishingOnRestart()
: Called after your activity has been stopped, prior to it being started again
-
What’s the difference between onCreate() and onStart()?
- The onCreate() method is called once during the Activity lifecycle, either when the application starts, or when the Activity has been destroyed and then recreated, for example during a configuration change.
- The onStart() method is called whenever the Activity becomes visible to the user, typically after onCreate() or onRestart().
- The onCreate() method is called once during the Activity lifecycle, either when the application starts, or when the Activity has been destroyed and then recreated, for example during a configuration change.
-
Scenario in which only onDestroy is called for an activity without onPause() and onStop()?
- If finish() is called in the OnCreate method of an activity, the system will invoke onDestroy() method directly.
- If finish() is called in the OnCreate method of an activity, the system will invoke onDestroy() method directly.
-
Why would you do the setContentView() in onCreate() of Activity class?
- As onCreate() of an Activity is called only once, this is the point where most initialization should go. It is inefficient to set the content in onResume() or onStart() (which are called multiple times) as the setContentView() is a heavy operation.
- As onCreate() of an Activity is called only once, this is the point where most initialization should go. It is inefficient to set the content in onResume() or onStart() (which are called multiple times) as the setContentView() is a heavy operation.
-
onSavedInstanceState() and onRestoreInstanceState() in activity?
OnRestoreInstanceState()
- When activity is recreated after it was previously destroyed, we can recover the saved state from the Bundle that the system passes to the activity. Both theonCreate()
andonRestoreInstanceState()
callback methods receive the same Bundle that contains the instance state information. But because theonCreate()
method is called whether the system is creating a new instance of your activity or recreating a previous one, you must check whether the state Bundle is null before you attempt to read it. If it is null, then the system is creating a new instance of the activity, instead of restoring a previous one that was destroyed.onSaveInstanceState()
- is a method used to store data before pausing the activity.
-
Launch modes in Android?
- Standard: It creates a new instance of an activity in the task from which it was started. Multiple instances of the activity can be created and multiple instances can be added to the same or different tasks.
- Example: Suppose there is an activity stack of A -> B -> C. Now if we launch B again with the launch mode as “standard”, the new stack will be A -> B -> C -> B.
- SingleTop: It is the same as the standard, except if there is a previous instance of the activity that exists in the top of the stack, then it will not create a new instance but rather send the intent to the existing instance of the activity.
- Example: Suppose there is an activity stack of A -> B. Now if we launch C with the launch mode as “singleTop”, the new stack will be A -> B -> C as usual.
- Now if there is an activity stack of A -> B -> C. If we launch C again with the launch mode as “singleTop”, the new stack will still be A -> B -> C.
- SingleTask: A new task will always be created and a new instance will be pushed to the task as the root one. So if the activity is already in the task, the intent will be redirected to onNewIntent() else a new instance will be created. At a time only one instance of activity will exist.
- Example: Suppose there is an activity stack of A -> B -> C -> D. Now if we launch D with the launch mode as “singleTask”, the new stack will be A -> B -> C -> D as usual.
- Now if there is an activity stack of A -> B -> C -> D. If we launch activity B again with the launch mode as “singleTask”, the new activity stack will be A -> B. Activities C and D will be destroyed.
- SingleInstance: Same as single task but the system does not launch any activities in the same task as this activity. If new activities are launched, they are done so in a separate task.
- Eg: Suppose there is an activity stack of A -> B -> C -> D. If we launch activity B again with the launch mode as “singleTask”, the new activity stack will be:
- Task1 — A -> B -> C and Task2 — D
- Standard: It creates a new instance of an activity in the task from which it was started. Multiple instances of the activity can be created and multiple instances can be added to the same or different tasks.
-
How does the activity respond when the user rotates the screen?
- When the screen is rotated, the current instance of activity is destroyed a new instance of the Activity is created in the ne