Mobile App Development Fundamentals
Mobile App Development Fundamentals
(Management)
IT - 31: MOBILE APPLICATION DEVELOPMENT (2020 Pattern)
(Semester - III)
[Link] Description Page numbers
1. Activity / Activities:
• It is a user interface. It contains both front-end/UI and back-end/UX
definition.
• In android front end definition is define by using XML definition and
back end definition or business logic is define by using Java or Koltin.
E.g.:
public class MainActivity extends Activity
{
-----
}
2. Service / Services:
• It is a service component that runs in the background to perform long-running
operations.
• It contains only back-end/UX definition and does not contains front-end/UI
details.
E.g.:
public class MyService extends Service
{
-----
}
3. Broadcast Receivers:
• It will receive a response then after only it broadcast the messages or
doing some action from other applications or from the system.
E.g.: Call Receiver, SMS Receiver, Notification, Radio etc
public class MyReceiver extends BroadcastReceiver
{
-----
}
4. Content Providers:
• A content provider component supplies data from one application to
others on request.
• Such request are handled by the methods of the ContentResolver class.
E.g.:
public class MyContentProvider extends ContentProvider
{
-----
}
EXAMPLE
• Now's let's we see the one E.g. of android component's through “Alarm” App
– Activity: It is a UI where we can set alarm.
– Content Provider: User Alarm data is saved at some place.
– Service: After user set a Alarm then there is a background
service or process is created which is continuously monitor to the time
interval to check whether current time interval is match to the alarm
time interval to fire an event.
– Broadcast Receiver: Broadcast Receiver receives a response to
handle the event at that interval. So that during that alarm time we
receives the notification, popup sound, etc.
DARVIK VIRTUAL MACHINE
The javac tool compiles the java source file into the class file.
The dx tool takes all the class files of your application and generates a single .dex file.
It is a platform-specific tool.
The Android Assets Packaging Tool (aapt) handles the packaging process.
INTRODUCTION JVM
As we know the modern JVM is high performance and provides excellent memory
management. But it needs to be optimized for low-powered handheld devices as well.
The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile
devices. It optimizes the virtual machine for memory, battery life and performance.
Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
The Dex compiler converts the class files into the .dex file that run on the Dalvik VM.
Multiple class files are converted into one dex file
JVM also has excellent memory management. However, for low-powered handheld
devices, it needs to be optimized. Being an android virtual machine, the Dalvik Virtual
Machine (DVM) is optimized for mobile devices. Thus optimizing the virtual machine
for memory, battery life and performance. It was written by Dan Bornstein, where
Dalvik represents the name of a town in Iceland. The class files are converted into
the .dex file by the Dex compiler. This file runs on the Dalvik VM. It is not only a
single file converted to a .dex file, but, multiple class files are converted into one .dex
file.
SQL LITE DATABASE
ANDROID DIALOGES
• A dialog is a small window that prompts the user to make a decision or enter
additional information.
• A dialog does not fill the screen and is normally used for modal events that
require users to take an action before user can proceed.
• In android dialogs are categorized into five types
1. Alert Dialog
2. DatePicker Dialog
3. TimePicker Dialog
4. Custom Dialog
1. Alert Dialog:
– Alert dialog is a dialog box with a small window where user can make
a decision or enter additional information.
• Title: This block is used to provide the title of alert dialog.
• Icon: This block is used to provide the icon for alert dialog.
• Content Block: This block can display message or a list or other
custom layout.
• Action Settings: Single dialog box can contain up to three action
button which are mention as follows
a. Positive: This button is used to receive and proceed
specific action. (E.g. "OK", "YES" Button)
b. Negative: This button is used to cancel the operation.
(E.g. "No" Button)
c. Neutral: This button is used if user do not want to
proceed with type specific action.
2. DatePicker Dialog:
– DatePicker dialog is also to be called as picker or Date picker.
– The DatePicker dialog allows the user to select date and assigned the
selected date to the specified view component.
– We use DatePicker to get the day, month and year from our device by
using Calendar reference.
3. TimePicker Dialog:
– TimePicker Dialog is also to be called as picker or Time picker.
– The TimePicker dialog allows the user to select time in hours and
minutes format but not in seconds.
– It assigned the result to the specified view component.
– We use TimePicker to get the hours and minute from our device by
using Calendar reference.
– Time picker dialog allows to select time in 12 hours (AM or PM) or 24
hours format.
4. Custom Dialog:
– Custom dialog nothing but designing the dialog activity as per our own
application requirement.
We can import any activity in the dialog or design the dialog by adding one by one
view or view group in the dialog definition
ANDROID FRAGMENT
• Android fragment is the part of activity.
• It is also known as sub-activity.
– E.g. Lets suppose we have an Activity A and another Activity B. If we
want to open some information then eventually we go to Activity B.
– This was the traditional navigation process implemented in so far
before Android 3.0
– After the Android 3.0 i.e. in Honeycomb (API level 11), here we have
define as blocks as fragment1, fragment2, etc.
– Here when we say block it means the user interface component or we
can say as a part of user interface.
• We can combine more than one fragments in one single activity.
• Fragment represent multiple screen inside one Activity.
• Android fragments have their own life cycle very similar to an android activity.
• So, android Fragment lifecycle is affected by activity lifecycle because
fragments are included in an activity.
• So, each fragment has its own fragment lifecycle methods that is affected by
activity lifecycle because fragments are embedded in an activity.
• The same fragment will be reuse across several activities.
• As fragment defines and manages its own layout and can handle its own input
events.
• Fragment can be added or removed or replaced while an activity runs.
• One of main advantage of fragments are they can better use in large screen
space such as tablets.
• It supports different layouts on portrait and landscape modes.
ANDROID INTENT
• An intent is a messaging object so we can use to request an action from an
another app component.
• Intent are used to communicate in between components.
• Android intents are mainly used to
1. Start the service
2. Launch an activity
3. Display a web page
4. Display list of contacts
5. Broadcast the message
6. Dial a phone call, receive call
7. Capture a photo using camera
Intents types:
• Intents are categorized into two types
1. Implicit Intent
2. Explicit Intent
[Link] Intent:
• Implicit intent are those that are already available in android as a
service.
• E.g. Contacts, Messages, Camera, Gallery, [Link], Google Map,
Wi-Fi, Bluetooth, Alarm, Calculator, etc.
• In implicit intent we does not need to specify the components but we
need to declare a action property to perform.
[Link] Intent:
• If we want to call our own activity which is created in our application
then such intent called as explicit intent.
• In explicit intent we can specify the component name to start the
activity.
• We generally use in explicit intent to start activity from our own
application.
• Because we know the class name of the activity or service name that
we want to start.
Creating Menu:
• For all menu types android provides a std. XML format to define menu items.
• Instead of building a menu in our activity code, we should define all menu and
it's items in a XML menu resource.
• So, that we can inflate these menu resource in our activity or a fragment.
• To define menu, we need to create a XML file inside our project/res/menu
directory.
Menu Elements:
• Following are the menu elements that are used in designing the menu details
1. <menu>:
a. This tag is used for defining the menu. It is a container for all
menu item.
b. A <menu> element must be the root node for the menu file and
can hold one or more <item> or <group> elements.
2. <item>:
a. This tag is used for defining the menu item. It represents a single
item in a menu.
b. This element may contain a nested <menu> element in order to
create a submenu.
3. <group>:
a. It is an optional tag. It is used as invisible container for <item>
elements.
b. It allows us to create categories menu items by creating menu
groups.
Menu Attributes:
Following are the menu attributes
1. android:id =>
This attribute is used as a resource id that is unique to the item.
2. android:title =>
It is a reference to a string that is used as the items title.
3. android:icon =>
It is a reference to a drawable that is used as the items icon.
REACT NATIVE
Following are the mobile application technologies that developers are using for
Android app development:
1. React Native:
• React Native is an open-source UI software framework created by Meta
Platforms Inc. and Facebook.
• React Native is the best JavaScript library to build native applications
for all devices and platforms.
• It is an open-source framework used to develop cross-platform
applications for Android, Android TV, iOS, macOS, tvOS, Web, and
Windows.
• Developers use ReactJS and JavaScript to create applications that
witness skyrocketing success on different platforms.
• Myntra, UberEats and Facebook are some of the apps that have been
developed using this framework.
ADVANTAGES
The third party Library provides the native app features which are not available in
React Native features. If we refer to React Native documentation, there are lots of
features that are not available (such as maps). Due to this, we need to add third party
libraries in our project. In this tutorial, we would learn how to add the third parties
libraries in our app (adding third party icons). There are different sets of bundled Icon
available. Some of them are listed below:
o AntDesign
o Entypo
o EvilIcons
o Feather
o FontAwesome
o FontAwesome 5
o Foundation
o Ionicons
o MaterialIcons
o MaterialCommunityIcons
o Octicons
o Zocial
o SimpleLineIcons
Installing Libraries
There are different ways and commands to install the libraries depending upon the
development OS and target OS. In this tutorial, we install the Ionicons libraries. To
install the Ionicons libraries on Windows, run the command: $ npm install react-
native-vector-icons --save.
FLUTER
• Flutter is a UI toolkit by Google, help in building native applications for
the web, mobile, and desktop.
• This UI toolkit is featured with fully customized widgets, which support
to create native applications in a short period.
The Flutter’s layered architecture ensures a faster rendering of
components.
FEATURES
Open-Source: Flutter is a free and open-source framework for developing mobile
applications.
Cross-platform: This feature allows Flutter to write the code once, maintain, and can
run on different platforms. It saves the time, effort, and money of the developers.
Hot Reload: Whenever the developer makes changes in the code, then these
changes can be seen instantaneously with Hot Reload. It means the changes
immediately visible in the app itself. It is a very handy feature, which allows the
developer to fix the bugs instantly.
Accessible Native Features and SDKs: This feature allows the app development
process easy and delightful through Flutter's native code, third-party integration, and
platform APIs. Thus, we can easily access the SDKs on both platforms.
VIEWS IN ANDROID
Views are used to create input and output fields in the an Android App. It can be
input text field, radio field, image field etc. They are same as, input text field, image
tag to show images, radio field in HTML.
The View-Group is the base class for layouts, which holds other Views and define
their properties. Actually an application comprises combination and nesting of
Views-Group and Views Classes.
Text View:
This class is used to display text on the android application screen. It also allows user
to optionally edit it. Although it contains text editing operations, the basic class does
not allow editing, So Edit Text class is included to do so.
Edit Text:
This class makes text to be editable in Android application. It helps in building the
data interface taken from any user, also contains certain features through which we
can hide the data which are confidential.
Image view:
Image view helps to display images in an android application. Any image can be
selected, we just have to paste our image in a drawable folder from where we can
access it. For example: In below Code “@drawable/ic_laucher” has been taken.
Check Box:
Checkbox is used in that applications where we have to select one option from
multiple provided. Checkbox is mainly used when 2 or more options are present
Radio Button:
Radio button is like checkbox, but there is slight difference between them. Radio
button is a two-states button that can be either checked or unchecked.
Button View:
This class is used to create a button on an application screen. Buttons are very
helpful in getting into a content. Android button represents a clickable push-button
widget.
Image Button View:
Image button is a button but it carries an image on it. We can put an image or a
certain text on it and when we click it provides the operations assigned to it.
Android Notification
Android Notification provides short, timely information about the action happened in
the application, even it is not running. The notification displays the icon, title and some
amount of the content text.
"title":"JSONParserTutorial",
"array":[
"company":"Google"
},
"company":"Facebook"
},
"company":"LinkedIn"
},
"company" : "Microsoft"
},
"company": "Apple"
],
"nested":{
"flag": true,
"random_number":1
}
WEB SERVICES ANS WEB VIEW
WEB SERVICES
WebView :
A View that displays web pages. This class is the basis upon which you can roll your
own web browser or simply display some online content within your Activity. It uses
the WebKit rendering engine to display web pages and includes methods to navigate
forward and backward through a history, zoom in and out, perform text searches and
more.
For example [Link]
WebView is a view that display web pages inside your application. You can also specify
HTML string and can show it inside your application using WebView. WebView makes
turns your application to a web application.
In order to add WebView to your application, you have to add <WebView> element
to your xml layout file. Its syntax is as follows −
<WebView xmlns:android="[Link]
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
DART PROGRAMMING
Dart is an open-source general-purpose programming language developed by
Google. It supports application development in both client and server-side. But it is
widely used for the development of android apps, iOS apps, IoT(Internet of Things),
and web applications using the Flutter Framework.
Syntactically, Dart bears a strong resemblance to Java, C, and JavaScript. It is a
dynamic object-oriented language with closure and lexical scope. The Dart language
was released in 2011 but came into popularity after 2015 with Dart 2.0.
Data
Type Keyword Description
[Link]
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:hint="Course name"
android:inputType="text" />
<EditText
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:hint="Duration (in year)"
android:inputType="number" />
<EditText
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="11dp"
android:hint="Description" />
<[Link]
android:id="@+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Course" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<[Link]
android:id="@+id/updateBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update" />
<[Link]
android:id="@+id/deleteBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete" />
<[Link]
android:id="@+id/displayBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display" />
</LinearLayout>
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
[Link]
package [Link].lab_j15;
//15. Write an android application using SQLite to create table and perform
CRUD operations
// (Example. COURSE table (ID, Name, Duration, Description), perform
ADD, UPDATE,
// DELETE and READ operations)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
findViewById([Link]).setOnClickListener(view ->
[Link]([Link]().toString(),
[Link]().toString()));
findViewById([Link]).setOnClickListener(view ->
[Link]([Link]().toString()));
findViewById([Link]).setOnClickListener(view -> {
ArrayList<CourseModel> list = [Link]();
String str = "ID Name Duration Description";
[Link](str);
});
}
}
[Link]
package [Link].lab_j15;
public CourseModel() {
[Link]
package [Link].lab_j15;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
[Link]("CREATE TABLE course(id INTEGER
PRIMARY KEY AUTOINCREMENT,name " +
"TEXT,duration TEXT,description TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
while ([Link]()) {
[Link] = [Link](0);
[Link] = [Link](1);
[Link] = [Link](2);
[Link] = [Link](3);
[Link](model);
}
return recordList;
}
SQLiteDatabase db = [Link]();
[Link]
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lstView"/>
</LinearLayout>
[Link]
package [Link].lab_j11;
//11. Demonstrate Array Adapter using List View to display list of fruits.
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
[Link](adapter);
}
}
3 Design android application for login activity by using TableLayout. Write
android code to check login credentials with username = "mca" and
password = "android". Display appropriate toast message to the user.
[Link]
activity_main.xml
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="Username : "
android:textSize="18sp" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:hint="Enter username"
android:inputType="text" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:text="Password : "
android:textSize="18sp" />
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:hint="Enter password"
android:inputType="textPassword" />
</TableRow>
<TableRow>
<[Link]
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="Login" />
</TableRow>
</TableLayout>
[Link]
package [Link].lab_j9;
//9. Design android application for login activity by using TableLayout. Write
android code to
// check login credentials with username = "mca" and password =
"android". Display appropriate
// toast message to the user
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
username = findViewById([Link]);
password = findViewById([Link]);
loginBtn = findViewById([Link]);
[Link](view -> {
if ([Link]().toString().equals("mca") &&
[Link]().toString().equals("android")) {
[Link]([Link], "Login Successfully",
Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Login failed",
Toast.LENGTH_SHORT).show();
}
});
}
}
[Link]
<uses-permission android:name="[Link].CALL_PHONE" />
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/mobNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter mobile no"
android:inputType="number"
android:maxEms="10"
android:padding="11dp" />
<[Link]
android:id="@+id/callBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call" />
</LinearLayout>
[Link]
package [Link].lab_j6;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
[Link](view -> {
Intent intent = new Intent(Intent.ACTION_CALL);
[Link]([Link]("[Link] + [Link]().toString()));
startActivity(intent);
});
}
}
[Link]
<uses-permission android:name="[Link]"/>
<uses-permission
android:name="[Link].BLUETOOTH_ADMIN"/>
<uses-permission
android:name="[Link].BLUETOOTH_CONNECT" />
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<[Link]
android:id="@+id/onBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On Bluetooth" />
<[Link]
android:id="@+id/offBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn Off Bluetooth" />
</LinearLayout>
[Link]
package [Link].lab_j7;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
onBtn = findViewById([Link]);
offBtn = findViewById([Link]);
final BluetoothAdapter bluetAdapter =
[Link]();
[Link](view -> {
if (![Link]()) {
if ([Link]([Link],
[Link].BLUETOOTH_CONNECT) !=
PackageManager.PERMISSION_GRANTED) {
[Link]();
}
}
});
[Link](view -> {
if ([Link]()) {
if ([Link]([Link],
[Link].BLUETOOTH_CONNECT) !=
PackageManager.PERMISSION_GRANTED) {
[Link]();
}
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<[Link]
android:id="@+id/onBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On Wi-Fi" />
<[Link]
android:id="@+id/offBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn Off Wi-Fi" />
</LinearLayout>
[Link]
package [Link].lab_j8;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
onBtn = findViewById([Link]);
offBtn = findViewById([Link]);
WifiManager wifiManager =
(WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
[Link](view -> {
if (![Link]()) {
[Link](true);
}
});
[Link](view -> {
if ([Link]()) {
[Link](false);
}
});
}
}