Professional Documents
Culture Documents
1st Unit Android
1st Unit Android
1st Unit Android
What is Android?
Android is an open source and Linux-based Operating System for mobile devices such
as smartphones and tablet computers. Android was developed by the Open Handset
Alliance, led by Google, and other companies.
Android offers a unified approach to application development for mobile devices which
means developers need only develop for Android, and their applications should be able
to run on different devices powered by Android.
The first beta version of the Android Software Development Kit (SDK) was released by
Google in 2007 where as the first commercial version, Android 1.0, was released in
September 2008.
Why Android ?
Features of Android
Android is a powerful operating system competing with Apple 4GS and supports great
features. Few of them are listed below −
1 Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.
2 Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC
and WiMAX.
3 Storage
SQLite, a lightweight relational database, is used for data storage
purposes.
4 Media support
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1,
MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.
5 Messaging
SMS and MMS
6 Web browser
Based on the open-source WebKit layout engine, coupled with Chrome's
V8 JavaScript engine supporting HTML5 and CSS3.
7 Multi-touch
Android has native support for multi-touch which was initially made
available in handsets such as the HTC Hero.
8 Multi-tasking
User can jump from one task to another and same time various application
can run simultaneously.
9 Resizable widgets
Widgets are resizable, so users can expand them to show more content or
shrink them to save space.
10 Multi-Language
Supports single direction and bi-directional text.
11 GCM
Google Cloud Messaging (GCM) is a service that lets developers send
short message data to their users on Android devices, without needing a
proprietary sync solution.
12 Wi-Fi Direct
A technology that lets apps discover and pair directly, over a high-
bandwidth peer-to-peer connection.
13 Android Beam
A popular NFC-based technology that lets users instantly share, just by
touching two NFC-enabled phones together.
Android Applications
Android applications are usually developed in the Java language using the Android
Software Development Kit.
Once developed, Android applications can be packaged easily and sold out either
through a store such as Google Play, SlideME, Opera Mobile Store, Mobango, F-
droid and the Amazon Appstore.
Android powers hundreds of millions of mobile devices in more than 190 countries
around the world. It's the largest installed base of any mobile platform and growing fast.
Every day more than 1 million new Android devices are activated wor ldwide.
History of Android
The code names of android ranges from A to N currently, such as Aestro, Blender,
Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwitch, Jelly
Bean, KitKat, Lollipop and Marshmallow. Let's understand the android history in a
sequence.
Advantages of Android App Development:
Android compared to other mobile platforms has a low barrier for entry. It
provides Software Development Kit (SDK) to the development community for
free, which in turn reduces the development and licensing costs.
Easy Integration:
Android is said to be the best mobile platform between the application and
processes architecture. The entire Android platform is ready for customization.
The developers can tweak and integrate the mobile app according to ones
business requirement.
Open Source:
The architecture of its SDK being open source it allows the developers to
communicate with the Android community about any upcoming expansion of
android mobile application development. This is what makes the platform so
attractive for handset manufacturers and wireless operators, resulting in fast
development of Android based apps.
Easy Adoption:
Android applications are built on java with the help of its robust set of features.
Anyone with Java knowledge can build applications in Android. The Java
developers find it easy and beneficial creating Android applications.
1. Simplicity
Many people have short attention spans and if you make your app difficult to
navigate then they will lose interest fast. If your customer cannot access their
information quickly and easily, they will become frustrated and do it another
way – possibly by using a competitor’s app
2. Speed
Fast loading screens are vital. No one likes waiting, particularly when all they
have to look at is a screen-loading symbol and this frustration soon gives way
to boredom resulting in a decision to seek something better. 3. Good image
resolution
While you have to balance app speed against functionality and resolution, you
have to ensure that what you have on screen is sufficiently detailed to make
the user experience worthwhile
4. Flexibility
There are three main mobile operating systems – iOS, Android, and Windows
– and in order to achieve the best out of your app, it needs to be available on
all of these. Android apps are easy to upload to the PlayStore, but iOS needs
to be tried and tested by Apple before they are allowed on the App Store.
5. Security
6. Search options
It sounds simple but many apps miss this important feature considering this is
something that many users make use of. The ability to search either the app
or the internet is important and while it’s not going to work so much for game-
based apps, it’s essential for the business and social variety.
8. Push notifications
Easier to send than emails and less likely to end up in a spam folder, push
notifications can be text, graphic, or a combination of both to send your users
content that they may be interested in
9. User feedback
While you would want to make the perfect app the first time around, there are
always going to be other ways to make it better and suit the user more. The
best way to understand that is to ask the user themselves.
10. Updates
Once you have your feedback, you can sort out how to make your app more
relevant to your customers, and send out updates periodically.
There are many more items which you use to build a good Android application. Apart
from coding for the application, you take care of various other resources like static
content that your code uses, such as bitmaps, colors, layout definitions, user interface
strings, animation instructions, and more. These resources are always maintained
separately in various sub-directories under res/ directory of the project.
This tutorial will explain you how you can organize your application resources, specify
alternative resources and access them in your applications.
1 anim/
XML files that define property animations. They are saved in res/anim/
folder and accessed from the R.anim class.
2 color/
XML files that define a state list of colors. They are saved in res/color/ and
accessed from the R.color class.
3 drawable/
Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps,
state lists, shapes, animation drawable. They are saved in res/drawable/
and accessed from the R.drawable class.
4 layout/
XML files that define a user interface layout. They are saved in res/layout /
and accessed from the R.layout class.
5 menu/
XML files that define application menus, such as an Options Menu, Context
Menu, or Sub Menu. They are saved in res/menu/ and accessed from
the R.menu class.
6 raw/
Arbitrary files to save in their raw form. You need to
call Resources.openRawResource() with the resource ID, which
is R.raw.filename to open such raw files.
7 values/
XML files that contain simple values, such as strings, integers, and colors.
For example, here are some filename conventions for resources you can
create in this directory −
arrays.xml for resource arrays, and accessed from the R.array class.
integers.xml for resource integers, and accessed from
the R.integer class.
bools.xml for resource boolean, and accessed from the R.bool class.
colors.xml for color values, and accessed from the R.color class.
dimens.xml for dimension values, and accessed from
the R.dimen class.
strings.xml for string values, and accessed from the R.string class.
styles.xml for styles, and accessed from the R.style class.
8 xml/
Arbitrary XML files that can be read at runtime by
calling Resources.getXML(). You can save various configuration files here
which will be used at run time.
Direct internal and external resources in software developm ent to deliver assigned
modules.
Actively engage in development activities associated with develop new solutions and
refining current solutions.
Provide general technical support and training to fellow colleagues and clients.
Collaborate and meet with the team to review status, identify potential blockers.
Debug and solve complex issues by translating business problems into technical
solutions.
Lead requirements gather meetings and reviews designs with the business.
Diagnose com plex issues, evaluate, recommend and execute the best resolution.
1. Native Apps
They are designed for specific operating systems such as Android, iOS,
and Windows. Apps make use of device features such as RAM,
camera, GPS, and so on.
2. Web Apps
A Web app is software that is kept in a distant location and distributed
via the Web using a browser interface. Emails, online shopping sales,
auction sites, weblogs, instant messaging apps, and other web apps are
popular.
3. Hybrid Apps
Hybrid apps are applications that are launched on a smartphone in the
same way that every other application is. What sets them apart is that
hybrids combine features from native apps and with components from
web apps.
The React Native design has a similar syntax to CSS, as it does not utilize
HTML or CSS. The messages from the JavaScript thread are used to exploit
native views.
1. Features of Flutter –
More rapid development.
Cross-platform.
Visuals that are both appealing and engaging.
Performance that is pretty similar to that of a native
2. Xamarin
Xamarin is an alternative cross-platform application development
framework for developing applications for Android and iOS. Because
they employ the C# programming language, the applications need fewer
lines of code. As a result, the process of coding is quicker. Also, it
allows us to rapidly transfer the scripts across other systems, such as
Windows and macOS.
Features of Xamarin –
Rapid Advancement
Appearance and touch of a native app
Compatibility with a variety of devices
3.Swiftic
Swiftic is a do-it-yourself mobile app platform that seeks to make it easy for
anybody to build unique applications for their company. It simplifies app
development by allowing programmers to integrate current material from the
internet rather than starting fresh
Features of Ionic –
App development for many platforms.
The user interface is consistent.
Enhanced performance.
The flexibility of the user
Native Scripts
Native Script is a precise open-source framework to build up native mobile
applications entrusted with Angular, Typescript, JavaScript, CSS, and Vue.js.
It was designed and developed by Progress.
Platform-independent user interfaces are defined with the use of XML files.
Then NativeScript operates the inferences represented in the XML files to call
the native UI components of each platform.
Features of jQuery –
Applications written with MIDP are normally designed for cell phones and
PDAs. They are known as midlets.
In theory, applications written using MIDP and CLDC should have the ability
to run on different Java ME-capable devices without any changes in their
code, which is consistent with Java’s "write once, run anywhere" mantra. In
practice, however, varying hardware specifications among devices, such as
graphical display sizes/resolutions and user interfaces, force developers to
make additional customizations.
Let’s start with the memory structure first. For effective memory management, JVM
divides memory into Stack and Heap.
Stack Memory
Java Stack memory is used for the execution of the thread. They contain method-
specific values which that are short-lived and references to the other objects in the heap
that are getting referred from the method.
Example:
Heap Memory
Java heap space is used to allocate memory to the objects. Whenever we create
Java/Kotlin objects, these will be allocated in the Heap memory.
Garbage collection process runs in the heap memory. Let’s go through the basic
garbage collection process and structure of the heap memory in detail
Contents
4 ART GC Overview
The objects that are being referenced are called ‘Live objects’ and those which are not
referenced are called ‘Dead objects’.
This process can be triggered at any time and we don’t have any control over it. We can
also request the system to initiate GC process in case we want to. But there is no
guarantee that it will be initiated by the system, it is up to the system to decide.
Step 1 : Marking
Most of us think that Garbage Collector marks dead objects and removes them. In
reality, it is exactly the opposite. Garbage Collector first finds the ‘Live objects’ and
marks them. This means the rest of the objects that are not marked are ‘Dead objects’.
Once Garbage Collector finds the ‘Dead objects’, it will remove them from the memory.
Basic GC process
As the number of objects increase, the above process i.e., Marking, Deletion and
Deletion with compacting is inefficient. As per the empirical analysis, most objects are
short-lived. Based on this analysis, the heap structure is divided into three generations.
Heap Structure
The heap structure is divided into three divisions namely, Young Generation, Tenured
or Old Generation, and Permanent Generation.
Types of Garbage Collectors
Serial GC
Parallel GC
Concurrent Mark and Sweep (CMS) collector
G1 Collector
These garbage collectors have their own advantages and disadvantages. As Android
Runtime (ART) uses the concept of CMS collector, we will only discuss Concurrent
Mark and Sweep (CMS) Collector here.
GC Algorithms
This collector is used to avoid long pauses during the Garbage collection process. It
scans heap memory using multiple threads. It uses parallel Stop the World mark-copy
algorithm in the young generation and concurrent mark-sweep algorithm in the Old
Generation.
Design and Architectural Patterns in
Android – An Introduction
A design pattern can be defined as a general repeatable solution to a commonly occurring problem
in software design. It won’t be the exact solution whereas it would just give a template to solve a
solution.
•They give the developer a selection of tried and tested solutions to work with
•They are language neutral and so can be applied to any language that supports object-orientation
•They aid communication by the very fact that they are well documented and can be researched if
that is not the case.
•They have a proven track record as they are already widely used and thus reduce the technical risk
to the project
•They are highly flexible and can be used in practically any type of application or domain
Creational Patterns
These design patterns provide a way to create objects while hiding the creation logic, rather than
instantiating objects directly using the new operator. This gives the program more flexibility in
deciding which objects need to be created for a given use case.
Structural Patterns
These design patterns concern class and object composition. The concept of inheritance is used to
compose interfaces and define ways to compose objects to obtain new functionalities.
Behavioural Patterns
These design patterns are specifically concerned with communication between objects.
Two main reasons for many codes to be in such bad shape is,
1. Continuous changes in UI.
2. Lack of an architecture that supported the flexibility that we needed.
View:
The View represents the UI components like CSS, jQuery, HTML etc. It is only responsible for
displaying the data that is received from the controller as the result. This also transforms the model(s)
into UI.
The Presenter is responsible for handling all UI events on behalf of the view. This receive input from
users via the View, then process the user’s data with the help of Model and passing the results back
to the View. Unlike view and controller, view and presenter are completely decoupled from each
other’s and communicate to each others by an interface. The architecture of MVP is shown below.
The View Model is responsible for exposing methods, commands, and other properties that help to
maintain the state of the view, manipulate the model as the result of actions on the vie w, and trigger
events in the view itself.
Simply any change that takes place within the model will be automatically updated in the view itself.
The Architecture of MVVM is shown below.
What are the Techniques for
Composing Applications in android
March 27, 2022 by StarTech City
In Android, there are so many techniques that are used to build an application.
And in this article, we are going to learn the BEST Techniques for composing
applications in android that are commonly used in GUI environments. We follow
many approaches; every developer or company has its thinking and techniques to
build an application but three are the most popular ones that are used by 90% of
the developers. Each technique has its advantages and disadvantages. Developers
choose techniques according to their needs.
Event-Based Programming
Event-Based Programming is based on generating events for every GUI element.
This approach makes GUI an event generator & reflects the choice of users. The
flow of the program and work depends on events. It is asynchronous
programming or model.
For Example: hovering the mouse or cursor over a button or link, or clicking on a
button or link may reflect other choices or significance.
Flowchart
MVC (Model View Controller) model
The Second Composing Application Technique in android is MVC. It is divided
into 3 parts, Model, View, and Controller. It is the way the information, and data is
been presented to the user & how the user interacts with the view.
In MVC, Controller and View depend on the Model. Controller to Update the data
or result, View to get the data.
MVC is of 2 types:
Common Auxiliary files are Menu, Binary Data, Localization Information, etc.
The importance of auxiliary files is increasing. Mobile devices are improved and
wireless facilities have been increasing. Auxiliary files are a considerable factor of
memory consumption to handle the auxiliary data, we use many resources which
are unnecessary and may use memory.
Auxiliary files needed by applications are many. For instance, there can be data
files whose contents are needed for creating a valid initial state. Usually, one
should compose applications so that even if some of the data files are missing, it
would be possible to run the application.
Concurrency In android
The Android SDK, as it is based on a subset of Java SDK, derived from the Apache
Harmony project, provides access to low-level concurrency constructs such
as java.lang.Thread, java.lang.Runnable, and the synchronized and volatile keywords.
These constructs are the most basic building blocks to achieve concurrency and
parallelism, and all the high-level asynchronous constructs are created around these
building blocks.
The most basic one, java.lang.Thread, is the class that is mostly used and is the
construct that creates a new independent line of execution in a Java program:
} Copy
myTread.start(); Copy
At this time, we will create an instance of our MyThread, and when we start it in the
second line, the system creates a thread inside the process and executes
the run() method.
Other helpful thread-related methods include the following:
The Runnable interface, which is another building block that comes from the Java API, is
an interface defined to specify and encapsulate code that is intended to be executed by
a Java thread instance or any other class that handles this Runnable:
package java.lang;
} Copy
In the following code, we basically created the Runnable subclass so that it implements
the run() method and can be passed and executed by a thread:
Thread.currentThread().getId());
...
}
} Copy
Now our Runnable subclass can be passed to Thread and is executed independently in
the concurrent line of execution:
thread.start(); Copy
While starting new threads is easy, concurrency is actually a very difficult thing to do.
Concurrent software faces many issues that fall into two broad categories: correctness
(producing consistent and correct results) and liveness (making progress towards
completion). Thread creation could also cause some performance overhead, and too
many threads can reduce the performance, as the OS will have switch between these
lines of execution.
This section of the tutorial will learn how to organize your applicatio n resources,
specify alternative resources, and access them in your application.
Alternative Resources
Your applicatio n needs to provide resources to support an alternative
configuration for a specific device. For example, you need to provide an
alternative picture of resources for different screen reso lutio ns, providing an
alternative string resources for different languages. At runtime, Andro id detects
the current device configuration, and load the appropriate resources for an
application.
To identify a set of alternative resources for specific configuration, following the
steps of:
Here is an example, to specify the default picture of the screen and high-
resolution image substitutio n.
MyProject/
src/
main/
java/
MyActivity.java
res/
drawable/
icon.png
background.png
drawable-hdpi/
icon.png
background.png
layout/
activity_main.xml
info.xml
values/
strings.xml
access to resources
In application development, we need access to defined resources, either
through code or through XML files. The follow ing sections describe how to
access these resources separately in two scenarios.
Examples
Access res / drawable / myimage.png, and set it to the ImageView, you would
use the follow ing code:
Requirements
To use the plugin in your game, use a supported version of Unity:
1. Select File > Build Settings. Make sure Android is selected as the current
platform.
2. Click the Player Settings button.
3. Under Other Settings, find Scripting Runtime Version and select .NET 4.6.
The plugin is provided as a Unity Package that you can import in your project.
Select Assets > Import Package > Custom Package and select
the .unitypackage file you downloaded.
Android Performance Tuner version 1.5.1 or higher with Unity 2017
Figure
1. Missing assembly reference.
5. Go to the Assets/AndroidPerformanceTuner/Runtime folder.
8. Restart Unity.
2. (For versions of Unity prior to 2019) Set the build system to Gradle.
Select File > Build Settings. Find Build System and select Gradle.
3. Add the internet access permission. Under Other Settings, find Internet
Access and select Require.
4. Enter your API key. Once the plugin is installed, you can enter it from
the Window > Android Performance Tuner > Setup menu. On this dialog,
select the Settings tab and enter the API key from your Google Cloud
project into the API key field.
Note: If you don't enter your API key, Android Performance Tuner won't send
your game pe