Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Report On Android Application Development

You are on page 1of 116

Report on Android

Application Development
- Prepared By Arnold Vaz

Report on Android Application Development - Prepared By Arnold Vaz Page 1


Introduction to Android Studio and Android –

Android Studio is Android's official IDE. It is purpose-built for Android to


accelerate Wer development and help We build the highest-quality apps
for every Android device.

Android is a mobile operating system developed by Google. It is used by


several smart phones and tablets. Developers can create programs for
Android using the free Android software developer kit (SDK). Android
programs are written in Java and run through a Java virtual machine JVM
that is optimized for mobile devices.

Android is thought of as a mobile operating system. It is currently used in


various devices such as mobiles, tablets, televisions etc. Android provides
a rich application framework that allows us to build innovative apps and
games for mobile devices in a Java language environment. Since Android
is an operating system, its purpose is to connect the user and the device.
For example, when a user wants to send a text, Android provides the user
Report on Android Application Development - Prepared By Arnold Vaz Page 2
with a button to tap. When the user taps the button, Android directs the
phone to send the text. The term "android" appears in US patents as early
as 1863 in reference to miniature human-like toy automatons. The term
android was used in a more modern sense by the French author Auguste
Villiers de l'Isle-Adam in his work tomorrow’s Eve (1886). This story
features an artificial humanlike robot named Hadaly.

Android is an open source and Linux-based Operating System for mobile


devices such as smart phones 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.
On June 27, 2012, at the Google I/O conference, Google announced the
next Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update,
with the primary aim of improving the user interface, both in terms of
functionality and performance.
The source code for Android is available under free and open source
software licenses. Google publishes most of the code under the Apache
License version 2.0 and the rest, Linux kernel changes, under the GNU
General Public License version 2.

Report on Android Application Development - Prepared By Arnold Vaz Page 3


Installation of Android Studio, Java JDK and
create project in Android Studio –
The official Integrated Development Environment (IDE) for developing
Android Apps is Android Studio, which Google supports. Java was
replaced by kotlin on May 7, 2019, as a preferred language for developing
Android Apps. But still, Java is being used for developing Android
Apps. Android Studio 3.6.1 has the following features.

 Gradle-based build support.

 UI components can be created by drag and drop features in the


laWet editor.

 Common Android designs and components can be created by


Template-based wizards.

 Built-in support for Google Cloud Platform enabling integration with


Firebase Cloud Messaging (Earlier 'Google Cloud Messaging') and
Google App Engine.

 Lint tools to catch performance, usefulness, version compatibility,


and other problems.

 System Requirements
Before downloading and installing Android Studio, the following
requirements are essential.

 Operating System Version - Microsoft Windows 7/8/10 (32-bit or 64-


bit).

 Random Access Memory (RAM) - Minimum 4 GB RAM and 8 GB RAM


recommended.

 Free Disk Space - Minimum 2 GB and 4 GB recommended.


Report on Android Application Development - Prepared By Arnold Vaz Page 4
 Minimum Required JDK Version - Java Development Kit (JDK) 8.

 Minimum Screen Resolution - 1280 * 800.resolution

Download and Install Android Studio


Download and Install Java JDK so, that the Android Studio
can work properly

Step 1

To download the Android Studio, visit the official Android Studio website in
Wer web browser.

Step 2

Click on the "Download Android Studio" option.

Step 3

Double click on the downloaded "Android Studio-ide.exe" file.

Step 4

"Android Studio Setup" will appear on the screen and click "Next" to
proceed.

Step 5

Select the components that We want to install and click on the "Next"
button.

Step 6

Now, browse the location where We want to install the Android Studio and
click "Next" to proceed.

Report on Android Application Development - Prepared By Arnold Vaz Page 5


Step 7

Choose a start menu folder for the "Android Studio" shortcut and click the
"Install" button to proceed.

Step 8

After the successful completion of the installation, click on the "Next"


button.

Step 9

Click on the "Finish" button to proceed.

 Android Studio Setup Configuration

Step 10

"Android Studio Setup Wizard" will appear on the screen with the welcome
wizard. Click on the "Next" button.

Step 11

Select (check) the "Standard" option if We are a beginner and do not have
any idea about Android Studio. It will install the most common settings and
options for We. Click "Next" to proceed.

Step 12

Now, select the user interface theme as We want. (I prefer Dark theme
(Dracula) that is most liked by the coders). Then, click on the "Next" button.

Step 13

Now, click on the "Finish" button to download all the SDK components.

Report on Android Application Development - Prepared By Arnold Vaz Page 6


And, the downloading and installation process of components gets started.

Step 14

After downloading all the necessary components, click on the "Finish"


button.

 First Program in Android Studio –

The Main Activity File -


package com.arnoldvaz.helloworld;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_main);

Report on Android Application Development - Prepared By Arnold Vaz Page 7


Manifest –
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.arnoldvaz.myapplication">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

The Strings File -


<resources>

<string name="app_name">HelloWorld</string>

Report on Android Application Development - Prepared By Arnold Vaz Page 8


<string name="hello_world">Hello world!</string>

<string name="menu_settings">Settings</string>

<string name="title_activity_main">MainActivity</string>

</resources>

The LaWet File -


<RelativeLaWet xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:laWet_width="match_parent"

android:laWet_height="match_parent" >

<TextView

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_centerHorizontal="true"

android:laWet_centerVertical="true"

android:padding="@dimen/padding_medium"

android:text="@string/hello_world"

tools:context=".MainActivity" />

</RelativeLaWet>

Report on Android Application Development - Prepared By Arnold Vaz Page 9


Virtual Device, Application Work and Android
Activity Life cycle –

Virtual Device -
An Android Virtual Device (AVD) is a configuration that defines the
characteristics of an Android phone, tablet, Wear OS, Android TV, or
Automotive OS device that We want to simulate in the Android Emulator.
The AVD Manager is an interface We can launch from Android Studio that
helps We create and manage AVDs.

To open the AVD Manager, do one of the following:

 Select Tools > AVD Manager.


 Click AVD Manager in the toolbar.
Open the AVD Manager by clicking Tools > AVD Manager.

Click Create Virtual Device, at the bottom of the AVD Manager dialog.
The Select Hardware page appears.

Select a hardware profile, and then click Next.

If We don't see the hardware profile We want, We can create or import a


hardware profile.

The System Image page appears.

Report on Android Application Development - Prepared By Arnold Vaz Page 10


Select the system image for a particular API level, and then click Next.

The Recommended tab lists recommended system images. The other tabs
include a more complete list. The right pane describes the selected
system image. x86 images run the fastest in the emulator.

If We see Download next to the system image, We need to click it to


download the system image. We must be connected to the internet to
download it.

The API level of the target device is important, because Wer app won't be
able to run on a system image with an API level that's less than that
required by Wer app, as specified in the minSdkVersion attribute of the
app manifest file. For more information about the relationship between
system API level and minSdkVersion, see Versioning Wer Apps.

If Wer app declares a <uses-library> element in the manifest file, the app
requires a system image in which that external library is present. If We
want to run Wer app on an emulator, create an AVD that includes the
required library. To do so, We might need to use an add-on component for

Report on Android Application Development - Prepared By Arnold Vaz Page 11


the AVD platform; for example, the Google APIs add-on contains the
Google Maps library.

The Verify Configuration page appears.

Change AVD properties as needed, and then click Finish.


Click Show Advanced Settings to show more settings, such as the skin.

The new AVD appears in the Wer Virtual Devices page or the Select
Deployment Target dialog.

Report on Android Application Development - Prepared By Arnold Vaz Page 12


Android Activity Life cycle –

Diagram 1 -

Report on Android Application Development - Prepared By Arnold Vaz Page 13


Diagram 2 -

Report on Android Application Development - Prepared By Arnold Vaz Page 14


Diagram 3 -

Report on Android Application Development - Prepared By Arnold Vaz Page 15


As a user navigates through, out of, and back to Wer app,
the Activity instances in Wer app transition through different states in their
lifecycle. The Activity class provides a number of callbacks that allow the
activity to know that a state has changed: that the system is creating,
stopping, or resuming an activity, or destroying the process in which the
activity resides.

Within the lifecycle callback methods, We can declare how Wer activity
behaves when the user leaves and re-enters the activity. For example, if
We're building a streaming video player, We might pause the video and
terminate the network connection when the user switches to another app.
When the user returns, We can reconnect to the network and allow the
user to resume the video from the same spot. In other words, each
callback allows We to perform specific work that's appropriate to a given
change of state. Doing the right work at the right time and handling
transitions properly make Wer app more robust and perform ant. For
example, good implementation of the lifecycle callbacks can help ensure
that Wer app avoids:

 Crashing if the user receives a phone call or switches to another app


while using Wer app.
 Consuming valuable system resources when the user is not actively using
it.
 Losing the user's progress if they leave Wer app and return to it at a later
time.
 Crashing or losing the user's progress when the screen rotates between
landscape and portrait orientation.

Report on Android Application Development - Prepared By Arnold Vaz Page 16


 OnCreate() Method –

On activity creation, the activity enters the Created state. In


the onCreate() method, We perform basic application startup logic that
should happen only once for the entire life of the activity. For example,
Wer implementation of onCreate() might bind data to lists, associate the
activity with a ViewModel, and instantiate some class-scope variables. This
method receives the parameter savedInstanceState, which is a Bundle object
containing the activity's previously saved state. If the activity has never
existed before, the value of the Bundle object is null.

If We have a lifecycle-aware component that is hooked up to the lifecycle


of Wer activity it will receive the ON_CREATE event. The method annotated
with @OnLifecycleEvent will be called so Wer lifecycle-aware component
can perform any setup code it needs for the created state.

The following example of the onCreate() method shows fundamental setup


for the activity, such as declaring the user interface (defined in an XML
laWet file), defining member variables, and configuring some of the UI. In
this example, the XML laWet file is specified by passing file’s resource
ID R.laWet.main_activity to setContentView().

 OnStart() Method –

When the activity enters the Started state, the system invokes this
callback. The onStart() call makes the activity visible to the user, as the app
prepares for the activity to enter the foreground and become interactive.
For example, this method is where the app initializes the code that
maintains the UI.

When the activity moves to the started state, any lifecycle-aware


component tied to the activity's lifecycle will receive the ON_START event.

The onStart() method completes very quickly and, as with the Created
state, the activity does not stay resident in the Started state. Once this
callback finishes, the activity enters the Resumed state, and the system
invokes the onResume() method.

Report on Android Application Development - Prepared By Arnold Vaz Page 17


 OnResume() Method –

When the activity enters the Resumed state, it comes to the foreground,
and then the system invokes the onResume() callback. This is the state in
which the app interacts with the user. The app stays in this state until
something happens to take focus away from the app. Such an event might
be, for instance, receiving a phone call, the user’s navigating to another
activity, or the device screen’s turning off.

When the activity moves to the resumed state, any lifecycle-aware


component tied to the activity's lifecycle will receive the ON_RESUME event.
This is where the lifecycle components can enable any functionality that
needs to run while the component is visible and in the foreground, such as
starting a camera preview.

When an interruptive event occurs, the activity enters the Paused state,
and the system invokes the onPause() callback.

If the activity returns to the Resumed state from the Paused state, the
system once again calls onResume() method. For this reason, We should
implement onResume() to initialize components that We release
during onPause(), and perform any other initializations that must occur
each time the activity enters the Resumed state.

 OnPause() Method –

The system calls this method as the first indication that the user is leaving
Wer activity (though it does not always mean the activity is being
destroyed); it indicates that the activity is no longer in the foreground
(though it may still be visible if the user is in multi-window mode). Use
the onPause() method to pause or adjust operations that should not
continue (or should continue in moderation) while the Activity is in the
Paused state, and that We expect to resume shortly. There are several
reasons why an activity may enter this state. When the activity moves to
the paused state, any lifecycle-aware component tied to the activity's
lifecycle will receive the ON_PAUSE event. This is where the lifecycle

Report on Android Application Development - Prepared By Arnold Vaz Page 18


components can stop any functionality that does not need to run while the
component is not in the foreground, such as stopping a camera preview.

We can also use the onPause() method to release system resources,


handles to sensors (like GPS), or any resources that may affect battery
life while Wer activity is paused and the user does not need them.
However, as mentioned above in the onResume() section, a Paused
activity may still be fully visible if in multi-window mode. As such, We
should consider using onStop() instead of onPause() to fully release or
adjust UI-related resources and operations to better support multi-
window mode.

 OnStop() Method –

When Wer activity is no longer visible to the user, it has entered


the Stopped state, and the system invokes the onStop() callback. This may
occur, for example, when a newly launched activity covers the entire
screen. The system may also call onStop() when the activity has finished
running, and is about to be terminated.

When the activity moves to the stopped state, any lifecycle-aware


component tied to the activity's lifecycle will receive the ON_STOP event.
This is where the lifecycle components can stop any functionality that
does not need to run while the component is not visible on the screen.

In the onStop() method, the app should release or adjust resources that are
not needed while the app is not visible to the user. For example, Wer app
might pause animations or switch from fine-grained to coarse-grained
location updates. Using onStop() instead of onPause() ensures that UI-
related work continues, even when the user is viewing Wer activity in
multi-window mode.

We should also use onStop() to perform relatively CPU-intensive shutdown


operations. For example, if We can't find a more opportune time to save
information to a database, We might do so during onStop().

Report on Android Application Development - Prepared By Arnold Vaz Page 19


 OnDestroy() Method –

onDestroy() is called before the activity is destroyed. The system invokes this
callback either because:

the activity is finishing (due to the user completely dismissing the activity or due
to finish() being called on the activity), or
the system is temporarily destroying the activity due to a configuration change
(such as device rotation or multi-window mode)

When the activity moves to the destroyed state, any lifecycle-aware component
tied to the activity's lifecycle will receive the ON_DESTROY event. This is where
the lifecycle components can clean up anything it needs to before the Activity is
destroyed.

Instead of putting logic in Wer Activity to determine why it is being destroyed We


should use a ViewModel object to contain the relevant view data for Wer Activity.
If the Activity is going to be recreated due to a configuration change the
ViewModel does not have to do anything since it will be preserved and given to
the next Activity instance. If the Activity is not going to be recreated then the
ViewModel will have the onCleared() method called where it can clean up any
data it needs to before being destroyed.

We can distinguish between these two scenarios with the isFinishing() method.

If the activity is finishing, onDestroy() is the final lifecycle callback the activity
receives. If onDestroy() is called as the result of a configuration change, the
system immediately creates a new activity instance and then calls onCreate() on
that new instance in the new configuration.

The onDestroy() callback should release all resources that have not yet been
released by earlier callbacks such as onStop().

Report on Android Application Development - Prepared By Arnold Vaz Page 20


Android Application Development (Coding and
Understanding the different Concepts) –
Buttons –
A user interface element the user can tap or click to perform an action.

Code –

<Button
android:id="@+id/button_id"
android:laWet_height="wrap_content"
android:laWet_width="wrap_content"
android:text="@string/self_destruct" />

To specify an action when the button is pressed, set a click listener on the
button object in the corresponding activity code:

public class MyActivity extends Activity {


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.laWet.content_laWet_id);

final Button button = findViewById(R.id.button_id);


button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
}
});
}
}

Every button is styled using the system's default button background, which is
often different from one version of the platform to another. If We are not
satisfied with the default button style, We can customize it. For more details and
code samples, see the Styling Wer Button guide.

Report on Android Application Development - Prepared By Arnold Vaz Page 21


For all XML style attributes available on Button see Button Attributes, TextView
Attributes, View Attributes. See the Styles and Themes guide to learn how to
implement and organize overrides to style-related attributes.

CheckBox –
Android CheckBox is a type of two state button either checked or unchecked.

There can be a lot of usage of checkboxes. For example, it can be used to


know the hobby of the user, activate/deactivate the specific action etc.

Android CheckBox class is the subclass of CompoundButton class.

Code -

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLaWet
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:laWet_width="match_parent"

android:laWet_height="match_parent"

tools:context="com.arnoldvaz.checkbox.MainActivity">

<CheckBox

android:id="@+id/checkBox"

Report on Android Application Development - Prepared By Arnold Vaz Page 22


android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_marginLeft="144dp"

android:laWet_marginTop="68dp"

android:text="Pizza"

app:laWet_constraintStart_toStartOf="parent"

app:laWet_constraintTop_toTopOf="parent" />

<CheckBox

android:id="@+id/checkBox2"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_marginLeft="144dp"

android:laWet_marginTop="28dp"

android:text="Coffee"

app:laWet_constraintStart_toStartOf="parent"

app:laWet_constraintTop_toBottomOf="@+id/checkBox" />

<CheckBox

android:id="@+id/checkBox3"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

Report on Android Application Development - Prepared By Arnold Vaz Page 23


android:laWet_marginLeft="144dp"

android:laWet_marginTop="28dp"

android:text="Burger"

app:laWet_constraintStart_toStartOf="parent"

app:laWet_constraintTop_toBottomOf="@+id/checkBox2" />

<Button

android:id="@+id/button"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_marginLeft="144dp"

android:laWet_marginTop="184dp"

android:text="Order"

app:laWet_constraintStart_toStartOf="parent"

app:laWet_constraintTop_toBottomOf="@+id/checkBox3" />

</android.support.constraint.ConstraintLaWet>

Report on Android Application Development - Prepared By Arnold Vaz Page 24


Activity Class –

package com.arnoldvaz.checkbox;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

CheckBox pizza,coffe,burger;

Button buttonOrder;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_main);

addListenerOnButtonClick();

public void addListenerOnButtonClick(){

//Getting instance of CheckBoxes and Button from the activty_main.xml file

pizza=(CheckBox)findViewById(R.id.checkBox);

Report on Android Application Development - Prepared By Arnold Vaz Page 25


coffe=(CheckBox)findViewById(R.id.checkBox2);

burger=(CheckBox)findViewById(R.id.checkBox3);

buttonOrder=(Button)findViewById(R.id.button);

//Applying the Listener on the Button click

buttonOrder.setOnClickListener(new View.OnClickListener(){

@Override

public void onClick(View view) {

int totalamount=0;

StringBuilder result=new StringBuilder();

result.append("Selected Items:");

if(pizza.isChecked()){

result.append("\nPizza 100Rs");

totalamount+=100;

if(coffe.isChecked()){

result.append("\nCoffe 50Rs");

totalamount+=50;

if(burger.isChecked()){

result.append("\nBurger 120Rs");

Report on Android Application Development - Prepared By Arnold Vaz Page 26


totalamount+=120;

result.append("\nTotal: "+totalamount+"Rs");

//Displaying the message on the toast

Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();

});

Android View Size Information –

dp or dip. > Density-independent Pixels - an abstract unit that is based on the


physical density of the screen. These units are relative to a 160 dpi screen, so
one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with
the screen density, but not necessarily in direct proportion.

 Android Event Listeners –


An event listener is an interface in the View class that contains a single callback
method. These methods will be called by the Android framework when the View
to which the listener has been registered is triggered by user interaction with
the item in the UI.

Included in the event listener interfaces are the following callback methods:

Report on Android Application Development - Prepared By Arnold Vaz Page 27


 onClick()
From View.OnClickListener. This is called when the user either touches the item
(when in touch mode), or focuses upon the item with the navigation-keys or
trackball and presses the suitable "enter" key or presses down on the trackball.

 onLongClick()
From View.OnLongClickListener. This is called when the user either touches and
holds the item (when in touch mode), or focuses upon the item with the
navigation-keys or trackball and presses and holds the suitable "enter" key or
presses and holds down on the trackball (for one second).

 onFocusChange()
From View.OnFocusChangeListener. This is called when the user navigates onto or
away from the item, using the navigation-keys or trackball.

 onKey()
From View.OnKeyListener. This is called when the user is focused on the item and
presses or releases a hardware key on the device.

 onTouch()
From View.OnTouchListener. This is called when the user performs an action
qualified as a touch event, including a press, a release, or any movement
gesture on the screen (within the bounds of the item).

 onCreateContextMenu()
From View.OnCreateContextMenuListener. This is called when a Context Menu is
being built (as the result of a sustained "long click"). See the discussion on
context menus in the Menus developer guide.

These methods are the sole inhabitants of their respective interface. To define
one of these methods and handle Wer events, implement the nested interface in
Wer Activity or define it as an anonymous class. Then, pass an instance of Wer
implementation to the respective View.set...Listener() method. (E.g.,
call setOnClickListener() and pass it Wer implementation of the OnClickListener.)
Report on Android Application Development - Prepared By Arnold Vaz Page 28
Notice that the onClick() callback in the above example has no return value, but
some other event listener methods must return a boolean. The reason depends
on the event. For the few that do, here's why:

onLongClick() - This returns a boolean to indicate whether We have


consumed the event and it should not be carried further. That is, return true to
indicate that We have handled the event and it should stop here; return false if
We have not handled it and/or the event should continue to any other on-click
listeners.

onKey() - This returns a boolean to indicate whether We have consumed the


event and it should not be carried further. That is, return true to indicate that We
have handled the event and it should stop here; return false if We have not
handled it and/or the event should continue to any other on-key listeners.

onTouch() - This returns a boolean to indicate whether Wer listener


consumes this event. The important thing is that this event can have multiple
actions that follow each other. So, if We return false when the down action
event is received, We indicate that We have not consumed the event and are
also not interested in subsequent actions from this event. Thus, We will not be
called for any other actions within the event, such as a finger gesture, or the
eventual up action event.

Remember that hardware key events are always delivered to the View currently
in focus. They are dispatched starting from the top of the View hierarchy, and
then down, until they reach the appropriate destination. If Wer View (or a child
of Wer View) currently has focus, then We can see the event travel through
the dispatchKeyEvent() method. As an alternative to capturing key events through
Wer View, We can also receive all of the events inside Wer Activity
with onKeyDown() and onKeyUp().

Also, when thinking about text input for Wer application, remember that many
devices only have software input methods. Such methods are not required to be
key-based; some may use voice input, handwriting, and so on. Even if an input
method presents a keyboard-like interface, it will generally not trigger
the onKeyDown() family of events. We should never build a UI that requires
specific key presses to be controlled unless We want to limit Wer application to
devices with a hardware keyboard. In particular, do not rely on these methods
to validate input when the user presses the return key; instead, use actions
like IME_ACTION_DONE to signal the input method how Wer application expects

Report on Android Application Development - Prepared By Arnold Vaz Page 29


to react, so it may change its UI in a meaningful way. Avoid assumptions about
how a software input method should work and just trust it to supply already
formatted text to Wer application.

 Android Gestures –

Android provides special types of touch screen events such as pinch , double
tap, scrolls , long presses and flinch. These are all known as gestures. Android
provides special types of touch screen events such as pinch , double tap,
scrolls , long presses and flinch. These are all known as gestures.
Android provides GestureDetector class to receive motion events and tell us
that these events correspond to gestures or not. To use it , We need to create
an object of GestureDetector and then extend another class
with GestureDetector.SimpleOnGestureListener to act as a listener and
override some methods.

Code -

GestureDetector myG;

myG = new GestureDetector(this,new Gesture());

class Gesture extends GestureDetector.SimpleOnGestureListener{

public boolean onSingleTapUp(MotionEvent ev) {

public void onLongPress(MotionEvent ev) {

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,

Report on Android Application Development - Prepared By Arnold Vaz Page 30


float distanceY) {

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

 Handling Pinch Gesture -


Android provides ScaleGestureDetector class to handle gestures like pinch e.t.c.
In order to use it, We need to instantiate an object of this class.

ScaleGestureDetector SGD;

SGD = new ScaleGestureDetector(this,new ScaleListener());

public boolean onTouchEvent(MotionEvent ev) {

SGD.onTouchEvent(ev);

return true;

private class ScaleListener extends


ScaleGestureDetector.SimpleOnScaleGestureListener {

@Override

public boolean onScale(ScaleGestureDetector detector) {

Report on Android Application Development - Prepared By Arnold Vaz Page 31


float scale = detector.getScaleFactor();

return true;

Main Activity –

package com.arnoldvaz.myapplication;

import android.app.Activity;

import android.graphics.Matrix;

import android.os.Bundle;

import android.view.MotionEvent;

import android.view.ScaleGestureDetector;

import android.widget.ImageView;

public class MainActivity extends Activity {

private ImageView iv;

private Matrix matrix = new Matrix();

private float scale = 1f;

private ScaleGestureDetector SGD;

@Override

Report on Android Application Development - Prepared By Arnold Vaz Page 32


protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_main);

iv=(ImageView)findViewById(R.id.imageView);

SGD = new ScaleGestureDetector(this,new ScaleListener());

public boolean onTouchEvent(MotionEvent ev) {

SGD.onTouchEvent(ev);

return true;

private class ScaleListener extends ScaleGestureDetector.

SimpleOnScaleGestureListener {

@Override

public boolean onScale(ScaleGestureDetector detector) {

scale *= detector.getScaleFactor();

scale = Math.max(0.1f, Math.min(scale, 5.0f));

matrix.setScale(scale, scale);

iv.setImageMatrix(matrix);

return true;

Report on Android Application Development - Prepared By Arnold Vaz Page 33


}

Layout Xml –

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:laWet_width="match_parent"

android:laWet_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"

tools:context=".MainActivity" >

<TextView android:text="Gestures

Example" android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:id="@+id/textview"

android:textSize="35dp"

android:laWet_alignParentTop="true"

android:laWet_centerHorizontal="true" />

Report on Android Application Development - Prepared By Arnold Vaz Page 34


<TextView

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="Tutorials point"

android:id="@+id/textView"

android:laWet_below="@+id/textview"

android:laWet_centerHorizontal="true"

android:textColor="#ff7aff24"

android:textSize="35dp" />

<ImageView

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:id="@+id/imageView"

android:src="@drawable/abc"

android:scaleType="matrix"

android:laWet_below="@+id/textView"

android:laWet_alignParentLeft="true"

android:laWet_alignParentStart="true"

android:laWet_alignParentBottom="true"

android:laWet_alignParentRight="true"

android:laWet_alignParentEnd="true" />

Report on Android Application Development - Prepared By Arnold Vaz Page 35


</RelativeLayout>

String File -

<resources>

<string name="app_name>My Application</string>

</resources>

Manifest file -

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.arnoldvaz.myapplication" >

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.sairamkrishna.myapplicationMainActivity"

android:label="@string/app_name" >

<intent-filter>

Report on Android Application Development - Prepared By Arnold Vaz Page 36


<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

 Android Fragments –
A Fragment represents a reusable portion of Wer app's UI. A fragment defines
and manages its own laWet, has its own lifecycle, and can handle its own input
events. Fragments cannot live on their own--they must be hosted by an activity
or another fragment. Fragment is a combination of an XML laWet file and a java
class much like an Activity . Using the support library, fragments are supported
back to all relevant Android versions. Fragments encapsulate views and logic
so that it is easier to reuse within activities.

According to the Android documentation, a fragment is a part of applications


user interface that is bound to an activity. Fragments have their lifecycle and
laWets or UI components. Fragments help enrich Wer UI design, pass data
between different screens, and adapt to different device configurations.
A fragment has its own laWet and its own behaviour with its own life cycle
callbacks. We can add or remove fragments in an activity while the activity is
running. We can combine multiple fragments in a single activity to build a multi-
pane UI. A fragment can be used in multiple activities.

Fragments are incomplete sentences. Usually, fragments are pieces of


sentences that have become disconnected from the main clause. One of the
easiest ways to correct them is to remove the period between the fragment and
the main clause. Other kinds of punctuation may be needed for the newly
combined sentence.

Report on Android Application Development - Prepared By Arnold Vaz Page 37


Report on Android Application Development - Prepared By Arnold Vaz Page 38
 Modularity -
Fragments introduce modularity and reusability into Wer activity’s UI by
allowing We to divide the UI into discrete chunks. Activities are an ideal place to
put global elements around Wer app's user interface, such as a navigation
drawer. Conversely, fragments are better suited to define and manage the UI of
a single screen or portion of a screen.

Consider an app that responds to various screen sizes. On larger screens, the
app should display a static navigation drawer and a list in a grid laWet. On
smaller screens, the app should display a bottom navigation bar and a list in a
linear laWet. Managing all of these variations in the activity can be unwieldy.
Separating the navigation elements from the content can make this process
more manageable. The activity is then responsible for displaying the correct
navigation UI while the fragment displays the list with the proper laWet.

Report on Android Application Development - Prepared By Arnold Vaz Page 39


Report on Android Application Development - Prepared By Arnold Vaz Page 40
 Creating Fragment –
A fragment represents a modular portion of the user interface within an activity.
A fragment has its own lifecycle, receives its own input events, and We can add
or remove fragments while the containing activity is running.

This document describes how to create a fragment and include it in an activity.

 Create a fragment class -


To create a fragment, extend the AndroidX Fragment class, and override its
methods to insert Wer app logic, similar to the way We would create
an Activity class. To create a minimal fragment that defines its own laWet,
provide Wer fragment's laWet resource to the base constructor

The Fragment library also provides more specialized fragment base classes:

DialogFragment

Displays a floating dialog. Using this class to create a dialog is a good


alternative to using the dialog helper methods in the Activity class, as
fragments automatically handle the creation and cleanup of the Dialog.
See Displaying dialogs with DialogFragment for more details.

PreferenceFragmentCompat

Displays a hierarchy of Preference objects as a list. We can


use PreferenceFragmentCompat to create a settings screen for Wer app.

 Add a fragment to an activity -


Generally, Wer fragment must be embedded within an
AndroidX FragmentActivity to contribute a portion of UI to that activity's
laWet. FragmentActivity is the base class for AppCompatActivity, so if We're
already subclassing AppCompatActivity to provide backward compatibility in
Wer app, then We do not need to change Wer activity base class.

Report on Android Application Development - Prepared By Arnold Vaz Page 41


We can add Wer fragment to the activity's view hierarchy either by defining
the fragment in Wer activity's laWet file or by defining a fragment container
in Wer activity's laWet file and then programmatically adding the fragment
from within Wer activity. In either case, We need to add
a FragmentContainerView that defines the location where the fragment should
be placed within the activity's view hierarchy. It is strongly recommended to
always use a FragmentContainerView as the container for fragments,
as FragmentContainerView includes fixes specific to fragments that other view
groups such as FrameLaWet do not provide.

Code –

public class ExampleActivity extends AppCompatActivity {

public ExampleActivity() {

super(R.laWet.example_activity);

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

if (savedInstanceState == null) {

getSupportFragmentManager().beginTransaction()

.setReorderingAllowed(true)

.add(R.id.fragment_container_view, ExampleFragment.class, null)

.commit();

Report on Android Application Development - Prepared By Arnold Vaz Page 42


2) <!-- res/laWet/example_activity.xml -->

<androidx.fragment.app.FragmentContainerView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/fragment_container_view"

android:laWet_width="match_parent"

android:laWet_height="match_parent" />

3) <!-- res/laWet/example_activity.xml -->

<androidx.fragment.app.FragmentContainerView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/fragment_container_view"

android:laWet_width="match_parent"

android:laWet_height="match_parent"

android:name="com.example.ExampleFragment" />

4) class ExampleFragment extends Fragment {

public ExampleFragment() {

super(R.laWet.example_fragment);

5) dependencies {

def fragment_version = "1.3.6"

Report on Android Application Development - Prepared By Arnold Vaz Page 43


// Java language implementation

implementation "androidx.fragment:fragment:$fragment_version"

// Kotlin

implementation "androidx.fragment:fragment-ktx:$fragment_version"

6) buildscript {

...

repositories {

google()

...

allprojects {

repositories {

google()

...

Report on Android Application Development - Prepared By Arnold Vaz Page 44


7) public class ExampleActivity extends AppCompatActivity {

public ExampleActivity() {

super(R.laWet.example_activity);

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

if (savedInstanceState == null) {

Bundle bundle = new Bundle();

bundle.putInt("some_int", 0);

getSupportFragmentManager().beginTransaction()

.setReorderingAllowed(true)

.add(R.id.fragment_container_view, ExampleFragment.class, bundle)

.commit();

8) class ExampleFragment extends Fragment {

public ExampleFragment() {

super(R.laWet.example_fragment);

Report on Android Application Development - Prepared By Arnold Vaz Page 45


@Override

public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {

int someInt = requireArguments().getInt("some_int");

 Run Application On Emulator –


Run on an emulator -
1. In Android Studio, create an Android Virtual Device (AVD) that the emulator can
use to install and run Wer app.
2. In the toolbar, select Wer app from the run/debug configurations drop-down
menu.
3. From the target device drop-down menu, select the AVD that We want to run
Wer app on.
4. Click Run .

Run on a real device –

Set up Wer device as follows:

1. Connect Wer device to Wer development machine with a USB cable. If We


developed on Windows, We might need to install the appropriate USB driver for
Wer device.
2. Perform the following steps to enable USB debugging in the Developer
options window:
a. Open the Settings app.
b. If Wer device uses Android v8.0 or higher, select System. Otherwise, proceed to
the next step.
c. Scroll to the bottom and select About phone.

Report on Android Application Development - Prepared By Arnold Vaz Page 46


d. Scroll to the bottom and tap Build number seven times.
e. Return to the previous screen, scroll to the bottom, and tap Developer options.
f. In the Developer options window, scroll down to find and enable USB debugging.

Run the app on Wer device as follows -

1. In Android Studio, select Wer app from the run/debug configurations drop-down
menu in the toolbar.
2. In the toolbar, select the device that We want to run Wer app on from the target
device drop-down menu.

 Intents in Android –
Report on Android Application Development - Prepared By Arnold Vaz Page 47
An intent is to perform an action on the screen. It is mostly used to start activity,
send broadcast receiver,start services and send message between two
activities. There are two intents available in android as Implicit Intents and
Explicit Intents. Android Intent is the message that is passed between
components such as activities, content providers, broadcast receivers, services
etc.

It is generally used with startActivity() method to invoke activity, broadcast


receivers etc.

The dictionary meaning of intent is intention or purpose. So, it can be described


as the intention to do action.

The LabeledIntent is the subclass of android.content.Intent class.

Android intents are mainly used to:

 Start the service


 Launch an activity
 Display a web page
 Display a list of contacts
 Broadcast a message
 Dial a phone call etc.

Code -

<?xml version = "1.0" encoding = "utf-8"?>

<android.support.constraint.ConstraintLaWet

xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:tools =


"http://schemas.android.com/tools" android:laWet_width = "match_parent"

android:laWet_height = "match_parent">

<LinearLaWet

android:laWet_width = "match_parent"

android:laWet_height = "match_parent"

Report on Android Application Development - Prepared By Arnold Vaz Page 48


android:gravity = "center"

android:orientation = "vertical">

<Button

android:laWet_width = "wrap_content"

android:laWet_height = "wrap_content"

android:text = "Send to another activitys"

android:id = "@+id/send"/>

</LinearLaWet>

</android.support.constraint.ConstraintLaWet>

2) <?xml version = "1.0" encoding = "utf-8"?>

<android.support.constraint.ConstraintLaWet xmlns:android =
"http://schemas.android.com/apk/res/android"

xmlns:app = "http://schemas.android.com/apk/res-auto"

xmlns:tools = "http://schemas.android.com/tools"

android:laWet_width = "match_parent"

android:laWet_height = "match_parent"

android:laWet_centerInParent = "true"

android:laWet_centerHorizontal = "true"

tools:context = ".SecondActivity">

<TextView

android:id = "@+id/data"

android:textSize = "20sp"

Report on Android Application Development - Prepared By Arnold Vaz Page 49


android:laWet_width = "wrap_content"

android:laWet_height = "wrap_content" />

</android.support.constraint.ConstraintLaWet>

3) import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_main);

Button send = findViewById(R.id.send);

send.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent send = new Intent(MainActivity.this, SecondActivity.class);

startActivity(send);

});

Report on Android Application Development - Prepared By Arnold Vaz Page 50


}

4) Intent send = new Intent(MainActivity.this, SecondActivity.class);

startActivity(send);

5) package com.arnoldvaz.myapplication;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_second);

TextView data=findViewById(R.id.data);

data.setText("This is second activity");

6) <?xml version = "1.0" encoding = "utf-8"?>

<manifest xmlns:android = "http://schemas.android.com/apk/res/android"

package = "com.example.andy.myapplication">

<application

android:allowBackup = "true"

Report on Android Application Development - Prepared By Arnold Vaz Page 51


android:icon = "@mipmap/ic_launcher"

android:label = "@string/app_name"

android:roundIcon = "@mipmap/ic_launcher_round"

android:supportsRtl = "true"

android:theme = "@style/AppTheme">

<activity android:name = ".MainActivity">

<intent-filter>

<action android:name = "android.intent.action.MAIN" />

<category android:name = "android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name = ".SecondActivity"></activity>

</application>

</manifest>

7) <activity android:name = ".SecondActivity"></activity>

<activity android:name = ".MainActivity""></activity>

 Threads in Android –

A thread is a thread of execution in a program. The Java Virtual Machine allows


an application to have multiple threads of execution running concurrently. Every
thread has a priority.

Threads with higher priority are executed in preference to threads with lower
priority. A Thread is a concurrent unit of execution. It has its own call stack for
methods being invoked, their arguments and local variables. Each virtual

Report on Android Application Development - Prepared By Arnold Vaz Page 52


machine instance has at least one main Thread running when it is started;
typically, there are several others for housekeeping.

When an application is launched in Android, it creates the first thread of


execution, known as the “main” thread. The main thread is responsible for
dispatching events to the appropriate user interface widgets as well as
communicating with components from the Android UI toolkit.

Android has four basic types of threads. We'll see other documentation talk
about even more, but we're going to focus on Thread , Handler , AsyncTask , and
something called HandlerThread. Use Thread. currentThread(). isAlive() to see if
the thread is alive[output should be true] which means thread is still running the
code inside the run() method or use Thread. When an application is launched in
Android, it creates the primary thread of execution, referred to as the “main”
thread. Most thread is liable for dispatching events to the acceptable interface
widgets also as communicating with components from the Android UI toolkit.

 Services in Android –

Report on Android Application Development - Prepared By Arnold Vaz Page 53


Report on Android Application Development - Prepared By Arnold Vaz Page 54
Android service is a component that is used to perform operations on the
background such as playing music, handle network transactions, interacting
content providers etc. It doesn't has any UI (user interface).

The service runs in the background indefinitely even if application is destroyed.

Moreover, service can be bounded by a component to perform interactivity and


inter process communication (IPC).

The android.app.Service is subclass of ContextWrapper class.

Life Cycle of Android Service -


There can be two forms of a service.The lifecycle of service can follow two
different paths: started or bound.

1. Started
2. Bound

Report on Android Application Development - Prepared By Arnold Vaz Page 55


1) Started Service

A service is started when component (like activity) calls startService() method,


now it runs in the background indefinitely. It is stopped by stopService() method.
The service can stop itself by calling the stopSelf() method.

2) Bound Service

A service is bound when another component (e.g. client) calls bind Service()
method. The client can unbind the service by calling the unbindService() method.

The service cannot be stopped until all clients unbind the service.

Code –

1) <?xml version="1.0" encoding="utf-8"?>

<RelativeLaWet xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:laWet_width="match_parent"

android:laWet_height="match_parent"

tools:context="arnoldvaz.com.androidservice.MainActivity">

<Button

android:id="@+id/buttonStart"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_alignParentTop="true"

Report on Android Application Development - Prepared By Arnold Vaz Page 56


android:laWet_centerHorizontal="true"

android:laWet_marginTop="74dp"

android:text="Start Service" />

<Button

android:id="@+id/buttonStop"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_centerHorizontal="true"

android:laWet_centerVertical="true"

android:text="Stop Service" />

<Button

android:id="@+id/buttonNext"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_alignParentBottom="true"

android:laWet_centerHorizontal="true"

android:laWet_marginBottom="63dp"

android:text="Next Page" />

</RelativeLaWet>

Report on Android Application Development - Prepared By Arnold Vaz Page 57


2) <?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLaWet
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:laWet_width="match_parent"

android:laWet_height="match_parent"

tools:context="com.arnoldvaz.androidservice.NextPage">

<TextView

android:id="@+id/textView"

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:laWet_marginEnd="8dp"

android:laWet_marginStart="8dp"

android:laWet_marginTop="200dp"

android:text="Next Page"

app:laWet_constraintEnd_toEndOf="parent"

app:laWet_constraintStart_toStartOf="parent"

app:laWet_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLaWet>

Service class

Now create the service implemenation class by inheriting the Service class and
overridding its callback methods.

Report on Android Application Development - Prepared By Arnold Vaz Page 58


File: MyService.java

package com.arnoldvaz.androidservice;

import android.app.Service;

import android.content.Intent;

import android.media.MediaPlayer;

import android.os.IBinder;

import android.support.annotation.Nullable;

import android.widget.Toast;

public class MyService extends Service {

MediaPlayer myPlayer;

@Nullable

@Override

public IBinder onBind(Intent intent) {

return null;

@Override

public void onCreate() {

Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();

myPlayer = MediaPlayer.create(this, R.raw.sun);

Report on Android Application Development - Prepared By Arnold Vaz Page 59


myPlayer.setLooping(false); // Set looping

@Override

public void onStart(Intent intent, int startid) {

Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();

myPlayer.start();

@Override

public void onDestroy() {

Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();

myPlayer.stop();

3) package com.arnoldvaz.androidservice;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class MainActivity extends AppCompatActivity implements


View.OnClickListener{

Report on Android Application Development - Prepared By Arnold Vaz Page 60


Button buttonStart, buttonStop,buttonNext;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_main);

buttonStart = findViewById(R.id.buttonStart);

buttonStop = findViewById(R.id.buttonStop);

buttonNext = findViewById(R.id.buttonNext);

buttonStart.setOnClickListener(this);

buttonStop.setOnClickListener(this);

buttonNext.setOnClickListener(this);

public void onClick(View src) {

switch (src.getId()) {

case R.id.buttonStart:

startService(new Intent(this, MyService.class));

break;

case R.id.buttonStop:

Report on Android Application Development - Prepared By Arnold Vaz Page 61


stopService(new Intent(this, MyService.class));

break;

case R.id.buttonNext:

Intent intent=new Intent(this,NextPage.class);

startActivity(intent);

break;

4) package com.arnoldvaz.androidservice;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class NextPage extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_next);

Report on Android Application Development - Prepared By Arnold Vaz Page 62


5) <?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.arnoldvaz.androidservice">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".NextPage"></activity>

<service

android:name=".MyService"

android:enabled="true" />

</application>

Report on Android Application Development - Prepared By Arnold Vaz Page 63


</manifest>

Services in Android are a special component that facilitates an application to


run in the background in order to perform long-running operation tasks. The
prime aim of a service is to ensure that the application remains active in the
background so that the user can operate multiple applications at the same time.

There are four different types of Android services: Bound Service – A bound
service is a service that has some other component (typically an Activity) bound
to it. A bound service provides an interface that allows the bound component
and the service to interact with each other. A service is started when an
application component, such as an activity, starts it by calling startService().
Once started, a service can run in the background indefinitely, even if the
component that started it is destroyed. 2. Bound. A service is bound when an
application component binds to it by calling bindService.

Service class uses the application's main thread, while IntentService creates a
worker thread and uses that thread to run the service. IntentService creates a
queue that passes one intent at a time to onHandleIntent(). Thus, implementing a
multi-thread should be made by extending Service class directly. Android
service is a component that is used to perform operations on the background
such as playing music, handle network transactions, interacting content
providers etc. It doesn't has any UI (user interface). The service runs in the
background indefinitely even if application is destroyed.

We stop a service via the stopService() method. No matter how frequently We


called the startService(intent) method, one call to the stopService() method
stops the service. A service can terminate itself by calling the stopSelf()
method.

We stop a service via the stopService() method. No matter how frequently We


called the startService(intent) method, one call to the stopService() method
stops the service. A service can terminate itself by calling the stopSelf()
method.

Report on Android Application Development - Prepared By Arnold Vaz Page 64


IntentService is an extension of the Service component class that handles
asynchronous requests (expressed as Intent s) on demand. Clients send
requests through Context. Android applications are broken down into four main
components: activities, services, content providers, and broadcast receivers.
Approaching Android from these four components gives the developer the
competitive edge to be a trendsetter in mobile application development.

To stop a IntentService, call the method stopService (Intent service). It request


that a given application service be stopped. If the service is not running, nothing
happens. Otherwise it is stopped.

 Menus is Android -
In android, Menu is a part of the user interface (UI) component which is used to handle some
common functionality around the application. By using Menus in our applications, we can
provide better and consistent user experience throughout the application.

There are three types of menus in Android: Popup, Contextual and Options. Each one
has a specific use case and code that goes along with it.

A context menu (also called contextual, shortcut, and pop up or pop-up menu) is a
menu in a graphical user interface (GUI) that appears upon user interaction, such as a
right-click mouse operation. Android Popup Menu: Android Popup Menu displays a list
of items in a vertical list which presents to the view that invoked the menu and useful
to provide an overflow of actions that related to specific content. The android overflow
menu also known as Option Menu is used to show a list of vertical menus with icons
inside it. Overflow menu is place above on android application screen at the top right
side of it. User can itself customize the over flow menu icons.

Report on Android Application Development - Prepared By Arnold Vaz Page 65


 Animations in Android –
Animations can add visual cues that notify users about what's going on in Wer app.
They are especially useful when the UI changes state, such as when new content loads
or new actions become available. Animations also add a polished look to Wer app,
which gives it a higher quality look and feel.

The animations are basically of three types as follows: Property Animation. View
Animation. Drawable Animation.

Code –

package com.arnoldvaz.myapplication;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.ImageView;

import android.widget.Toast;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.laWet.activity_main);

Report on Android Application Development - Prepared By Arnold Vaz Page 66


public void clockwise(View view){

ImageView image = (ImageView)findViewById(R.id.imageView);

Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),

R.anim.myanimation);

image.startAnimation(animation);

public void zoom(View view){

ImageView image = (ImageView)findViewById(R.id.imageView);

Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(),

R.anim.clockwise);

image.startAnimation(animation1);

public void fade(View view){

ImageView image = (ImageView)findViewById(R.id.imageView);

Animation animation1 =

AnimationUtils.loadAnimation(getApplicationContext(),

R.anim.fade);

image.startAnimation(animation1);

Report on Android Application Development - Prepared By Arnold Vaz Page 67


public void blink(View view){

ImageView image = (ImageView)findViewById(R.id.imageView);

Animation animation1 =

AnimationUtils.loadAnimation(getApplicationContext(),

R.anim.blink);

image.startAnimation(animation1);

public void move(View view){

ImageView image = (ImageView)findViewById(R.id.imageView);

Animation animation1 =

AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);

image.startAnimation(animation1);

public void slide(View view){

ImageView image = (ImageView)findViewById(R.id.imageView);

Animation animation1 =

AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);

image.startAnimation(animation1);

Report on Android Application Development - Prepared By Arnold Vaz Page 68


2) <RelativeLaWet

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:laWet_width="match_parent"

android:laWet_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="Alert Dialog"

android:id="@+id/textView"

android:textSize="35dp"

android:laWet_alignParentTop="true"

android:laWet_centerHorizontal="true" />

<TextView

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

Report on Android Application Development - Prepared By Arnold Vaz Page 69


android:text="Tutorialspoint"

android:id="@+id/textView2"

android:textColor="#ff3eff0f"

android:textSize="35dp"

android:laWet_below="@+id/textView"

android:laWet_centerHorizontal="true" />

<ImageView

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:id="@+id/imageView"

android:src="@drawable/abc"

android:laWet_below="@+id/textView2"

android:laWet_alignRight="@+id/textView2"

android:laWet_alignEnd="@+id/textView2"

android:laWet_alignLeft="@+id/textView"

android:laWet_alignStart="@+id/textView"/>

<Button

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="zoom"

android:id="@+id/button"

Report on Android Application Development - Prepared By Arnold Vaz Page 70


android:laWet_below="@+id/imageView"

android:laWet_alignParentLeft="true"

android:laWet_alignParentStart="true"

android:laWet_marginTop="40dp"

android:onClick="clockwise"/>

<Button

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="clockwise"

android:id="@+id/button2"

android:laWet_alignTop="@+id/button"

android:laWet_centerHorizontal="true"

android:onClick="zoom"/>

<Button

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="fade"

android:id="@+id/button3"

android:laWet_alignTop="@+id/button2"

android:laWet_alignParentRight="true"

android:laWet_alignParentEnd="true"

Report on Android Application Development - Prepared By Arnold Vaz Page 71


android:onClick="fade"/>

<Button

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="blink"

android:onClick="blink"

android:id="@+id/button4"

android:laWet_below="@+id/button"

android:laWet_alignParentLeft="true"

android:laWet_alignParentStart="true" />

<Button

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="move"

android:onClick="move"

android:id="@+id/button5"

android:laWet_below="@+id/button2"

android:laWet_alignRight="@+id/button2"

android:laWet_alignEnd="@+id/button2"

android:laWet_alignLeft="@+id/button2"

android:laWet_alignStart="@+id/button2" />

Report on Android Application Development - Prepared By Arnold Vaz Page 72


<Button

android:laWet_width="wrap_content"

android:laWet_height="wrap_content"

android:text="slide"

android:onClick="slide"

android:id="@+id/button6"

android:laWet_below="@+id/button3"

android:laWet_toRightOf="@+id/textView"

android:laWet_toEndOf="@+id/textView" />

</RelativeLaWet>

3) <?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<scale xmlns:android="http://schemas.android.com/apk/res/android"

android:fromXScale="0.5"

android:toXScale="3.0"

android:fromYScale="0.5"

android:toYScale="3.0"

android:duration="5000"

android:pivotX="50%"

android:pivotY="50%" >

Report on Android Application Development - Prepared By Arnold Vaz Page 73


</scale>

<scale xmlns:android="http://schemas.android.com/apk/res/android"

android:startOffset="5000"

android:fromXScale="3.0"

android:toXScale="0.5"

android:fromYScale="3.0"

android:toYScale="0.5"

android:duration="5000"

android:pivotX="50%"

android:pivotY="50%" >

</scale>

</set>

4) <?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<rotate xmlns:android="http://schemas.android.com/apk/res/android"

android:fromDegrees="0"

android:toDegrees="360"

android:pivotX="50%"

android:pivotY="50%"

android:duration="5000" >

Report on Android Application Development - Prepared By Arnold Vaz Page 74


</rotate>

<rotate xmlns:android="http://schemas.android.com/apk/res/android"

android:startOffset="5000"

android:fromDegrees="360"

android:toDegrees="0"

android:pivotX="50%"

android:pivotY="50%"

android:duration="5000" >

</rotate>

</set>

5) <?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"

android:interpolator="@android:anim/accelerate_interpolator" >

<alpha

android:fromAlpha="0"

android:toAlpha="1"

android:duration="2000" >

</alpha>

Report on Android Application Development - Prepared By Arnold Vaz Page 75


<alpha

android:startOffset="2000"

android:fromAlpha="1"

android:toAlpha="0"

android:duration="2000" >

</alpha>

</set>

6) <?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha android:fromAlpha="0.0"

android:toAlpha="1.0"

android:interpolator="@android:anim/accelerate_interpolator"

android:duration="600"

android:repeatMode="reverse"

android:repeatCount="infinite"/>

</set>

7) <?xml version="1.0" encoding="utf-8"?>

<set

xmlns:android="http://schemas.android.com/apk/res/android"

android:interpolator="@android:anim/linear_interpolator"

android:fillAfter="true">

Report on Android Application Development - Prepared By Arnold Vaz Page 76


<translate

android:fromXDelta="0%p"

android:toXDelta="75%p"

android:duration="800" />

</set>

8) <?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"

android:fillAfter="true" >

<scale

android:duration="500"

android:fromXScale="1.0"

android:fromYScale="1.0"

android:interpolator="@android:anim/linear_interpolator"

android:toXScale="1.0"

android:toYScale="0.0" />

</set>

9) <?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.arnoldvaz.myapplication" >

<application

android:allowBackup="true"

Report on Android Application Development - Prepared By Arnold Vaz Page 77


android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.example.animation.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

10) <resources>

<string name="app_name">My Application</string>

</resources>

Report on Android Application Development - Prepared By Arnold Vaz Page 78


 List View in Android –

Advertisements. Android ListView is a view which groups several items and display
them in vertical scrollable list. The list items are automatically inserted to the list
using an Adapter that pulls content from a source such as an array or database.
Android ListView is a ViewGroup that is used to display the list of items in multiple
rows and contains an adapter that automatically inserts the items into the list. The
main purpose of the adapter is to fetch data from an array or database and insert each
item that placed into the list for the desired result.

A list view is an adapter view that does not know the details, such as type and
contents, of the views it contains. Instead list view requests views on demand from a
ListAdapter as needed, such as to display new views as the user scrolls up or down. In
order to display items in the list, call setAdapter.

Report on Android Application Development - Prepared By Arnold Vaz Page 79


An adapter actually bridges between UI components and the data source that fill data
into UI Component. Adapter holds the data and send the data to adapter view, the view
can takes the data from adapter view and shows the data on different views like as
spinner, list view, grid view etc.
The ListView and GridView are subclasses of AdapterView and they can be populated
by binding them to an Adapter, which retrieves data from an external source and
creates a View that represents each data entry.
Android provides several subclasses of Adapter that are useful for retrieving different
kinds of data and building views for an AdapterView ( i.e. ListView or GridView). The
common adapters are ArrayAdapter,Base
Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListAdapt
er. We will see separate examples for both the adapters.

 SQLite Database in Android –


SQLite is an open-source relational database i.e. used to perform database operations
on android devices such as storing, manipulating or retrieving persistent data from the
database. It is embedded in android bydefault. SQLite is a opensource SQL database
that stores data to a text file on a device. Android comes in with built in SQLite
database implementation.

SQLite is very good for testing. We don't need to set up any API or install any library to
access data from SQLite. SQLite is cross-platform which means that it can be used on
Android application built on Java, and as well as cross-platform application built on
React Native.

An SQLite database is normally stored in a single ordinary disk file. However, in


certain circumstances, the database might be stored in memory. ... Instead, a new
database is created purely in memory. The database ceases to exist as soon as the
database connection is closed.
Adobe uses SQLite as the application file format for their Photoshop Lightroom
product. SQLite is also a standard part of the Adobe Integrated Runtime (AIR). It is
reported that Acrobat Reader also uses SQLite. Airbus confirms that SQLite is being
used in the flight software for the A350 XWB family of aircraft.

Exposes methods to manage a SQLite database.

SQLiteDatabase has methods to create, delete, execute SQL commands, and perform
other common database management tasks.

See the Notepad sample application in the SDK for an example of creating and
managing a database.

Report on Android Application Development - Prepared By Arnold Vaz Page 80


Database names must be unique within an application, not across all applications.

SQLite is a opensource SQL database that stores data to a text file on a device.
Android comes in with built in SQLite database implementation.
SQLite supports all the relational database features. In order to access this database,
you don't need to establish any kind of connections for it like JDBC,ODBC e.t.c

Code -

1) package com.arnoldvaz.myapplication;

import android.content.Context;

import android.content.Intent;

import android.support.v7.app.ActionBarActivity;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ListView;

Report on Android Application Development - Prepared By Arnold Vaz Page 81


import java.util.ArrayList;

import java.util.List;

public class MainActivity extends ActionBarActivity {

public final static String EXTRA_MESSAGE = "MESSAGE";

private ListView obj;

DBHelper mydb;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mydb = new DBHelper(this);

ArrayList array_list = mydb.getAllCotacts();

ArrayAdapter arrayAdapter=new
ArrayAdapter(this,android.R.layout.simple_list_item_1, array_list);

obj = (ListView)findViewById(R.id.listView1);

obj.setAdapter(arrayAdapter);

obj.setOnItemClickListener(new OnItemClickListener(){

@Override

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

Report on Android Application Development - Prepared By Arnold Vaz Page 82


// TODO Auto-generated method stub

int id_To_Search = arg2 + 1;

Bundle dataBundle = new Bundle();

dataBundle.putInt("id", id_To_Search);

Intent intent = new Intent(getApplicationContext(),DisplayContact.class);

intent.putExtras(dataBundle);

startActivity(intent);

});

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

@Override

public boolean onOptionsItemSelected(MenuItem item){

Report on Android Application Development - Prepared By Arnold Vaz Page 83


super.onOptionsItemSelected(item);

switch(item.getItemId()) {

case R.id.item1:Bundle dataBundle = new Bundle();

dataBundle.putInt("id", 0);

Intent intent = new Intent(getApplicationContext(),DisplayContact.class);

intent.putExtras(dataBundle);

startActivity(intent);

return true;

default:

return super.onOptionsItemSelected(item);

public boolean onKeyDown(int keycode, KeyEvent event) {

if (keycode == KeyEvent.KEYCODE_BACK) {

moveTaskToBack(true);

return super.onKeyDown(keycode, event);

Report on Android Application Development - Prepared By Arnold Vaz Page 84


2) package com.arnoldvaz.myapplication;

import android.os.Bundle;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.content.Intent;

import android.database.Cursor;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import android.widget.Toast;

public class DisplayContact extends Activity {

int from_Where_I_Am_Coming = 0;

private DBHelper mydb ;

TextView name ;

Report on Android Application Development - Prepared By Arnold Vaz Page 85


TextView phone;

TextView email;

TextView street;

TextView place;

int id_To_Update = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_display_contact);

name = (TextView) findViewById(R.id.editTextName);

phone = (TextView) findViewById(R.id.editTextPhone);

email = (TextView) findViewById(R.id.editTextStreet);

street = (TextView) findViewById(R.id.editTextEmail);

place = (TextView) findViewById(R.id.editTextCity);

mydb = new DBHelper(this);

Bundle extras = getIntent().getExtras();

if(extras !=null) {

int Value = extras.getInt("id");

if(Value>0){

Report on Android Application Development - Prepared By Arnold Vaz Page 86


//means this is the view part not the add contact part.

Cursor rs = mydb.getData(Value);

id_To_Update = Value;

rs.moveToFirst();

String nam =
rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_NAME));

String phon =
rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_PHONE));

String emai =
rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_EMAIL));

String stree =
rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_STREET));

String plac =
rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_CITY));

if (!rs.isClosed()) {

rs.close();

Button b = (Button)findViewById(R.id.button1);

b.setVisibility(View.INVISIBLE);

name.setText((CharSequence)nam);

name.setFocusable(false);

name.setClickable(false);

Report on Android Application Development - Prepared By Arnold Vaz Page 87


phone.setText((CharSequence)phon);

phone.setFocusable(false);

phone.setClickable(false);

email.setText((CharSequence)emai);

email.setFocusable(false);

email.setClickable(false);

street.setText((CharSequence)stree);

street.setFocusable(false);

street.setClickable(false);

place.setText((CharSequence)plac);

place.setFocusable(false);

place.setClickable(false);

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

Report on Android Application Development - Prepared By Arnold Vaz Page 88


Bundle extras = getIntent().getExtras();

if(extras !=null) {

int Value = extras.getInt("id");

if(Value>0){

getMenuInflater().inflate(R.menu.display_contact, menu);

} else{

getMenuInflater().inflate(R.menu.menu_main menu);

return true;

public boolean onOptionsItemSelected(MenuItem item) {

super.onOptionsItemSelected(item);

switch(item.getItemId()) {

case R.id.Edit_Contact:

Button b = (Button)findViewById(R.id.button1);

b.setVisibility(View.VISIBLE);

name.setEnabled(true);

name.setFocusableInTouchMode(true);

name.setClickable(true);

Report on Android Application Development - Prepared By Arnold Vaz Page 89


phone.setEnabled(true);

phone.setFocusableInTouchMode(true);

phone.setClickable(true);

email.setEnabled(true);

email.setFocusableInTouchMode(true);

email.setClickable(true);

street.setEnabled(true);

street.setFocusableInTouchMode(true);

street.setClickable(true);

place.setEnabled(true);

place.setFocusableInTouchMode(true);

place.setClickable(true);

return true;

case R.id.Delete_Contact:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage(R.string.deleteContact)

.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {

Report on Android Application Development - Prepared By Arnold Vaz Page 90


mydb.deleteContact(id_To_Update);

Toast.makeText(getApplicationContext(), "Deleted Successfully",

Toast.LENGTH_SHORT).show();

Intent intent = new Intent(getApplicationContext(),MainActivity.class);

startActivity(intent);

})

.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {

// User cancelled the dialog

});

AlertDialog d = builder.create();

d.setTitle("Are you sure");

d.show();

return true;

default:

return super.onOptionsItemSelected(item);

Report on Android Application Development - Prepared By Arnold Vaz Page 91


public void run(View view) {

Bundle extras = getIntent().getExtras();

if(extras !=null) {

int Value = extras.getInt("id");

if(Value>0){

if(mydb.updateContact(id_To_Update,name.getText().toString(),

phone.getText().toString(), email.getText().toString(),

street.getText().toString(), place.getText().toString())){

Toast.makeText(getApplicationContext(), "Updated",
Toast.LENGTH_SHORT).show();

Intent intent = new Intent(getApplicationContext(),MainActivity.class);

startActivity(intent);

} else{

Toast.makeText(getApplicationContext(), "not Updated",


Toast.LENGTH_SHORT).show();

} else{

if(mydb.insertContact(name.getText().toString(), phone.getText().toString(),

email.getText().toString(), street.getText().toString(),

place.getText().toString())){

Toast.makeText(getApplicationContext(), "done",

Toast.LENGTH_SHORT).show();

} else{

Report on Android Application Development - Prepared By Arnold Vaz Page 92


Toast.makeText(getApplicationContext(), "not done",

Toast.LENGTH_SHORT).show();

Intent intent = new Intent(getApplicationContext(),MainActivity.class);

startActivity(intent);

3) package com.arnoldvaz.myapplication;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Hashtable;

import android.content.ContentValues;

import android.content.Context;

import android.database.Cursor;

import android.database.DatabaseUtils;

import android.database.sqlite.SQLiteOpenHelper;

import android.database.sqlite.SQLiteDatabase;

public class DBHelper extends SQLiteOpenHelper {

Report on Android Application Development - Prepared By Arnold Vaz Page 93


public static final String DATABASE_NAME = "MyDBName.db";

public static final String CONTACTS_TABLE_NAME = "contacts";

public static final String CONTACTS_COLUMN_ID = "id";

public static final String CONTACTS_COLUMN_NAME = "name";

public static final String CONTACTS_COLUMN_EMAIL = "email";

public static final String CONTACTS_COLUMN_STREET = "street";

public static final String CONTACTS_COLUMN_CITY = "place";

public static final String CONTACTS_COLUMN_PHONE = "phone";

private HashMap hp;

public DBHelper(Context context) {

super(context, DATABASE_NAME , null, 1);

@Override

public void onCreate(SQLiteDatabase db) {

// TODO Auto-generated method stub

db.execSQL(

"create table contacts " +

"(id integer primary key, name text,phone text,email text, street text,place text)"

);

Report on Android Application Development - Prepared By Arnold Vaz Page 94


@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

// TODO Auto-generated method stub

db.execSQL("DROP TABLE IF EXISTS contacts");

onCreate(db);

public boolean insertContact (String name, String phone, String email, String
street,String place) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues contentValues = new ContentValues();

contentValues.put("name", name);

contentValues.put("phone", phone);

contentValues.put("email", email);

contentValues.put("street", street);

contentValues.put("place", place);

db.insert("contacts", null, contentValues);

return true;

public Cursor getData(int id) {

SQLiteDatabase db = this.getReadableDatabase();

Cursor res = db.rawQuery( "select * from contacts where id="+id+"", null );

Report on Android Application Development - Prepared By Arnold Vaz Page 95


return res;

public int numberOfRows(){

SQLiteDatabase db = this.getReadableDatabase();

int numRows = (int) DatabaseUtils.queryNumEntries(db,


CONTACTS_TABLE_NAME);

return numRows;

public boolean updateContact (Integer id, String name, String phone, String email,
String street,String place) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues contentValues = new ContentValues();

contentValues.put("name", name);

contentValues.put("phone", phone);

contentValues.put("email", email);

contentValues.put("street", street);

contentValues.put("place", place);

db.update("contacts", contentValues, "id = ? ", new String[] { Integer.toString(id) } );

return true;

public Integer deleteContact (Integer id) {

Report on Android Application Development - Prepared By Arnold Vaz Page 96


SQLiteDatabase db = this.getWritableDatabase();

return db.delete("contacts",

"id = ? ",

new String[] { Integer.toString(id) });

public ArrayList<String> getAllCotacts() {

ArrayList<String> array_list = new ArrayList<String>();

//hp = new HashMap();

SQLiteDatabase db = this.getReadableDatabase();

Cursor res = db.rawQuery( "select * from contacts", null );

res.moveToFirst();

while(res.isAfterLast() == false){

array_list.add(res.getString(res.getColumnIndex(CONTACTS_COLUMN_NAME)));

res.moveToNext();

return array_list;

4) <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

Report on Android Application Development - Prepared By Arnold Vaz Page 97


xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/textView"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:textSize="30dp"

android:text="Data Base" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Tutorials Point"

android:id="@+id/textView2"

android:layout_below="@+id/textView"

Report on Android Application Development - Prepared By Arnold Vaz Page 98


android:layout_centerHorizontal="true"

android:textSize="35dp"

android:textColor="#ff16ff01" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageView"

android:layout_below="@+id/textView2"

android:layout_centerHorizontal="true"

android:src="@drawable/logo"/>

<ScrollView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/scrollView"

android:layout_below="@+id/imageView"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true">

Report on Android Application Development - Prepared By Arnold Vaz Page 99


<ListView

android:id="@+id/listView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true" >

</ListView>

</ScrollView>

</RelativeLayout>

5) <?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/scrollView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

tools:context=".DisplayContact" >

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="370dp"

android:paddingBottom="@dimen/activity_vertical_margin"

Report on Android Application Development - Prepared By Arnold Vaz Page 100


android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin">

<EditText

android:id="@+id/editTextName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_marginTop="5dp"

android:layout_marginLeft="82dp"

android:ems="10"

android:inputType="text" >

</EditText>

<EditText

android:id="@+id/editTextEmail"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/editTextStreet"

android:layout_below="@+id/editTextStreet"

android:layout_marginTop="22dp"

android:ems="10"

Report on Android Application Development - Prepared By Arnold Vaz Page 101


android:inputType="textEmailAddress" />

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/editTextName"

android:layout_alignParentLeft="true"

android:text="@string/name"

android:textAppearance="?android:attr/textAppearanceMedium" />

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/editTextCity"

android:layout_alignParentBottom="true"

android:layout_marginBottom="28dp"

android:onClick="run"

android:text="@string/save" />

<TextView

android:id="@+id/textView2"

Report on Android Application Development - Prepared By Arnold Vaz Page 102


android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/editTextEmail"

android:layout_alignLeft="@+id/textView1"

android:text="@string/email"

android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView

android:id="@+id/textView5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/editTextPhone"

android:layout_alignLeft="@+id/textView1"

android:text="@string/phone"

android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView

android:id="@+id/textView4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/editTextEmail"

android:layout_alignLeft="@+id/textView5"

android:text="@string/street"

Report on Android Application Development - Prepared By Arnold Vaz Page 103


android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText

android:id="@+id/editTextCity"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignRight="@+id/editTextName"

android:layout_below="@+id/editTextEmail"

android:layout_marginTop="30dp"

android:ems="10"

android:inputType="text" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBaseline="@+id/editTextCity"

android:layout_alignBottom="@+id/editTextCity"

android:layout_alignParentLeft="true"

android:layout_toLeftOf="@+id/editTextEmail"

android:text="@string/country"

android:textAppearance="?android:attr/textAppearanceMedium" />

Report on Android Application Development - Prepared By Arnold Vaz Page 104


<EditText

android:id="@+id/editTextStreet"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/editTextName"

android:layout_below="@+id/editTextPhone"

android:ems="10"

android:inputType="text" >

<requestFocus />

</EditText>

<EditText

android:id="@+id/editTextPhone"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/editTextStreet"

android:layout_below="@+id/editTextName"

android:ems="10"

android:inputType="phone|text" />

</RelativeLayout>

</ScrollView>

Report on Android Application Development - Prepared By Arnold Vaz Page 105


6) <?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="app_name">Address Book</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<string name="Add_New">Add New</string>

<string name="edit">Edit Contact</string>

<string name="delete">Delete Contact</string>

<string name="title_activity_display_contact">DisplayContact</string>

<string name="name">Name</string>

<string name="phone">Phone</string>

<string name="email">Email</string>

<string name="street">Street</string>

<string name="country">City/State/Zip</string>

<string name="save">Save Contact</string>

<string name="deleteContact">Are you sure, you want to delete it.</string>

<string name="yes">Yes</string>

<string name="no">No</string>

</resources>

7) <?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@+id/item1"

Report on Android Application Development - Prepared By Arnold Vaz Page 106


android:icon="@drawable/add"

android:title="@string/Add_New" >

</item>

</menu>

8) <?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item

android:id="@+id/Edit_Contact"

android:orderInCategory="100"

android:title="@string/edit"/>

<item

android:id="@+id/Delete_Contact"

android:orderInCategory="100"

android:title="@string/delete"/>

</menu>

9) <?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.arnoldvaz.myapplication" >

Report on Android Application Development - Prepared By Arnold Vaz Page 107


<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name=".MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".DisplayContact"/>

</application>

</manifest>

Report on Android Application Development - Prepared By Arnold Vaz Page 108


 Toast in Android –
Andorid Toast can be used to display information for the short period of time. A
toast contains message to be displayed quickly and disappears after sometime. The
android.

These operations are as follows:


1. Add the listener on Button and this Button will show a toast message. btn.
setOnClickListener(new View. ...
2. Now, Create a toast message. The Toast. ...
3. Display the created Toast Message using the show() method of the Toast class. Syntax:
public void show ()

android.widget.Toast. A toast is a view containing a quick little message for the user.
The toast class helps you create and show those. When the view is shown to the user,
appears as a floating view over the application. It will never receive focus.

A Toast is a feedback message. It takes a very little space for displaying while
overall activity is interactive and visible to the user. It disappears after a few
seconds. It disappears automatically. If user wants permanent visible
message, Notification can be used.
Another type of Toast is custom Toast, in which images can be used instead of
a simple message.

 SharedPreferences in Android –
Android provides many ways of storing data of an application. One of this way is called
Shared Preferences. Shared Preferences allow you to save and retrieve data in the
form of key,value pair.
In order to use shared preferences, you have to call a method getSharedPreferences()
that returns a SharedPreference instance pointing to the file that contains the values
of preferences.

SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES,


Context.MODE_PRIVATE);

Editor editor = sharedpreferences.edit();


editor.putString("key", "value");
editor.commit();

Report on Android Application Development - Prepared By Arnold Vaz Page 109


import android.content.Context;

import android.content.SharedPreferences;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText ed1,ed2,ed3;

Button b1;

public static final String MyPREFERENCES = "MyPrefs" ;

public static final String Name = "nameKey";

public static final String Phone = "phoneKey";

public static final String Email = "emailKey";

SharedPreferences sharedpreferences;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Report on Android Application Development - Prepared By Arnold Vaz Page 110


ed1=(EditText)findViewById(R.id.editText);

ed2=(EditText)findViewById(R.id.editText2);

ed3=(EditText)findViewById(R.id.editText3);

b1=(Button)findViewById(R.id.button);

sharedpreferences = getSharedPreferences(MyPREFERENCES,
Context.MODE_PRIVATE);

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String n = ed1.getText().toString();

String ph = ed2.getText().toString();

String e = ed3.getText().toString();

SharedPreferences.Editor editor = sharedpreferences.edit();

editor.putString(Name, n);

editor.putString(Phone, ph);

editor.putString(Email, e);

editor.commit();

Toast.makeText(MainActivity.this,"Thanks",Toast.LENGTH_LONG).show();

Report on Android Application Development - Prepared By Arnold Vaz Page 111


}

});

2) <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Shared Preference "

android:id="@+id/textView"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:textSize="35dp" />

Report on Android Application Development - Prepared By Arnold Vaz Page 112


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Tutorials Point"

android:id="@+id/textView2"

android:layout_below="@+id/textView"

android:layout_centerHorizontal="true"

android:textSize="35dp"

android:textColor="#ff16ff01" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText"

android:layout_below="@+id/textView2"

android:layout_marginTop="67dp"

android:hint="Name"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

<EditText

Report on Android Application Development - Prepared By Arnold Vaz Page 113


android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText2"

android:layout_below="@+id/editText"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:hint="Pass" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText3"

android:layout_below="@+id/editText2"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"

android:hint="Email" />

<Button

android:layout_width="wrap_content"

Report on Android Application Development - Prepared By Arnold Vaz Page 114


android:layout_height="wrap_content"

android:text="Save"

android:id="@+id/button"

android:layout_below="@+id/editText3"

android:layout_centerHorizontal="true"

android:layout_marginTop="50dp" />

</RelativeLayout>

3) <?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.arnoldvaz.myapplication" >

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name=".MainActivity"

android:label="@string/app_name" >

<intent-filter>

Report on Android Application Development - Prepared By Arnold Vaz Page 115


<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

Conclusion of this Report –


I've learned through my report that Android and Androd Development field is a much
more diverse operating system, carrer than iOS. Android has grown rapidly over the
past 8 years becoming the most used smartphone operating system in the world. It's
because Android doesn't release 1 phone from 1 company with 1 new OS every year, but
countless phones from numerous companies, adding their own twist, throughout the
year, developing gradually day-by-day. Android's ability to customize is unparalleled
compared to Apple's software allowing the user to change and customize nearly every
aspect of Android which most iPhone and other OS users wouldn't dream possible. I
am not one to say that Android is better or worse than one OS, but is unique and
incomparable to other mobile operating systems.

Report on Android Application Development - Prepared By Arnold Vaz Page 116

You might also like