0% found this document useful (0 votes)
17 views49 pages

Mobile App Development Fundamentals

Mca android notes

Uploaded by

mrk750mrk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views49 pages

Mobile App Development Fundamentals

Mca android notes

Uploaded by

mrk750mrk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

S.Y. M.C.A.

(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

• SQLite is an open source database.


• SQLite supports standard relational database features.
• The important feature of the SQLite database is, it is a local database or inbuilt
available with android.
• So, it does not required any server or any ODBC or JDBC drivers for connecting
with database.
• SQLite database saves it's data into a text file and stores it into it's local device
(Any android device such as Android mobiles, tablets, etc.)
• Android comes with in built SQLite database implementation. So, we don't
required to install it manually.
• Similarly we don't required to download any supporting library for SQLite
database implementation.
• To create and upgrade a database in our android application we create a
subclass of the SQLiteOpenHelper class.

DATA TYPES
• INTEGER : Signed integer such as 1, 2, 3, etc.
• REAL: A floating point value.
• TEXT: String or text value.
• NULL: null value.
• BLOB: Binary Large Object.
– It is used to store bits value in the table.
– BOLBs are sometimes used for storing JPG,
– MP#, MOV files etc.
– Many programmers are not preferred to use BLOB records but instead
we can store images in seperate folder and store only the file name in
the database.
ANDROID SQLITE Cursor
• The result set from a query operation is called as the cursor in the android.
• We loop through the cursor items to process each line of a search result.
• Cursor contain several methods to navigate the records.

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.

Fragment class is having some of major methods which will be participate in


an fragment life cycle, these methods are shown below
1. onAttach()
2. onCreate()
3. onCreateView()
4. onActivityCreated()
5. onStart()
6. onResume()
7. onPause()
8. onStop()
9. onDestroyView()
10. onDestroy()
11. onDetach()
There are five states of a fragment in fragment life cycle.
1. Initialized
2. Created
3. Started
4. Resumed
5. Destroyed
Fragment Life Cycle Methods:
1. onAttach():
• The very first method to be called when the Fragment has been
associated with the activity i.e. Fragment is attached to an activity.
• This method executes only once during the lifetime of a Fragment.
2. onCreate():
• This method is called while initializes the Fragment by adding all the
required attributes and components.
3. onCreateView():
• This method is called to create the user interface of the Fragment.
• The root of the Fragment’s layout is returned as the View component
by using this method to draw the UI.
4. onActivityCreated():
• This method is called while an activity has been created in which the
Fragment exists.
• Fragment View hierarchy is also instantiated before this function call.
5. onStart():
• This method is called while Fragment view is becoming visible to the
user.
6. onResume():
• This method is called while Fragment view is completely visible to the
user.
• User can interact with Fragment view.
7. onPause():
• It indicates that the user is leaving the Fragment.
• User can not interact with Fragment View.
• System call this method to commit the changes made to the Fragment.
8. onStop():
• This method is called to terminate the functioning and visibility of
Fragment from the user’s screen.
• Fragment View is invisible to the user.
• User can not interact with Fragment View.
9. onDestroyView():
• System calls this method to clean up all kinds of resources as well as
view hierarchy associated with the Fragment.
• Fragment View is destroyed.
10. onDestroy():
• It is called to perform the final clean up of Fragment’s state and its
lifecycle.
• Here Fragment is destroyed.
11. onDetach():
• The system executes this method to disassociate the Fragment from its
host activity.
• So, Fragment is removed from an Activity.

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.

Explicit Intent Types:


• Explicit intent we can use in 4 different ways.
a. Normal Switching
b. Switching with data
c. Switching with result data
d. Switching with data and result data
ANDROID MENUS
• Menu is defined in an android by using resource directory of an android
application.
• Menu is classified into different categories such as
1. Option Menu
2. Context Menu
3. Popup Menu
• Similarly also we can design above all types of menu items in the form of
single or nested form.
• Above all types of menu which can be inflated using MenuItem class or
Inflator method.

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 best 10 benefits of React Native


1. Amazing cost reduction as compared to platform Native development.
2. Fewer resources are needed
3. React Native uses JavaScript that has matured over the years.
4. Less workforce required.
5. Completely free to use.
6. There is a major community of developers present on this platform.
7. The “Hot Reloading” feature serves great benefits.
8. No need to compromise on the performance of the applications.
9. The applications built on React Native look and feel like Native applications.
10. The modular architecture saves a lot of hustle.

React Third Party Libraries

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.

Create a project and run 'npm install --save react-native-vector-icons'


as D:\ReactNative\navigationApp>npm install --save react-native-vector-icons

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.

In general, creating a mobile application is a very complex and challenging


task. There are many frameworks available, which provide excellent
features to develop mobile applications. For developing mobile apps,
Android provides a native framework based on Java and Kotlin language,
while iOS provides a framework based on Objective-C/Swift language. Thus,
we need two different languages and frameworks to develop applications
for both OS. Today, to overcome form this complexity, there are several
frameworks have introduced that support both OS along with desktop apps.
These types of the framework are known as cross-platform development
tools.

The cross-platform development framework has the ability to write one


code and can deploy on the various platform (Android, iOS, and Desktop). It
saves a lot of time and development efforts of developers. There are
several tools available for cross-platform development, including web-
based tools, such as Ionic from Drifty Co. in 2013, Phonegap from Adobe,
Xamarin from Microsoft, and React Native form Facebook. Each of these
frameworks has varying degrees of success in the mobile industry. In
recent, a new framework has introduced in the cross-platform development
family named Flutter developed from Google.

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.

Minimal code: Flutter app is developed by Dart programming language,


which uses JIT and AOT compilation to improve the overall start-up time,
functioning and accelerates the performance. JIT enhances the development
system and refreshes the UI without putting extra effort into building a new
one.

Widgets: The Flutter framework offers widgets, which are capable of


developing customizable specific designs. Most importantly, Flutter has two
sets of widgets: Material Design and Cupertino widgets that help to provide a
glitch-free experience on all platforms.
MOBILE APPLICATION DEVELOPMENT
• Mobile application development is the process to making software for
smartphones and digital assistants, most commonly for Android and IOS.
• The software can be preinstalled on the device, downloaded from a mobile
app store or accessed through a mobile web browser.
• The programming and markup languages used for this kind of software
development include Java, Swift, C# and HTML5.
• Mobile app development is rapidly growing. From retail, telecommunications
and e-commerce to insurance, healthcare and government, organizations
across industries must meet user expectations for real-time, convenient ways
to conduct transactions and access information.
• Today, mobile devices and the mobile applications that unlock their value, are
the most popular way for people and businesses to connect to the internet.

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.

View Group Class

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.

Set Android Notification Properties


The properties of Android notification are set
using [Link] object. Some of the notification properties are
mention below:

o setSmallIcon(): It sets the icon of notification.


o setContentTitle(): It is used to set the title of notification.
o setContentText(): It is used to set the text message.
o setAutoCancel(): It sets the cancelable property of notification.
o setPriority(): It sets the priority of notification.

JSON (JavaScript Object Notation)


is a straightforward data exchange format to interchange the server’s data, and it is
a better alternative for XML. This is because JSON is a lightweight and structured
language. Android supports all the JSON classes such as JSONStringer, JSONObject,
JSONArray, and all other forms to parse the JSON data and fetch the required
information by the program. JSON’s main advantage is that it is a language-
independent, and the JSON object will contain data like a key/value pair. In general,
JSON nodes will start with a square bracket ([) or with a curly bracket ({). The square
and curly bracket’s primary difference is that the square bracket ([) represents the
beginning of a JSONArray node. Whereas, the curly bracket ({) represents
a JSONObject. So one needs to call the appropriate method to get the data.
Sometimes JSON data start with [. We then need to use the getJSONArray() method
to get the data. Similarly, if it starts with {, then we need to use
the getJSONobject() method.
{

"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

A web service is a standard used for exchanging information between applications or


systems of heterogeneous type. Software applications written in various
programming languages and running on various platforms can use web services to
exchange information over Internet using http protocol.
For exchanging information between two or more different types of applications,
irrespective of their language or platform, a standard is set and that is known as Web
Service. For example, we can use the Web Service for exchanging information
between an android application and java or .net application.
Example
[Link] This is the webservice json example. This is in json
format. which is used to read the ip from this url. You can read this data and use for
your need. But you are not going to display as an page.

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

int, double, Numbers in Dart are used to represent


Number num numeric literals

Strings String Strings represent a sequence of characters

Booleans bool It represents Boolean values true and false

Lists List It is an ordered group of objects

It represents a set of values as key-value


Maps Map pairs
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)

[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];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

MyDBClass mydb = new MyDBClass(this);


EditText name, duration, description;
TextView txt = findViewById([Link]);
name = findViewById([Link]);
duration = findViewById([Link]);
description = findViewById([Link]);
findViewById([Link]).setOnClickListener(view ->
[Link]([Link]().toString(), [Link]().toString(),
[Link]().toString()));

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";

for (int i = 0; i < [Link](); i++) {

str += "\n" + [Link](i).id + " " + [Link](i).name + " " +


[Link](i).duration + " " + [Link](i).description;

[Link](str);
});

}
}
[Link]
package [Link].lab_j15;

public class CourseModel {


String name, duration, description;
int id;

public CourseModel() {

[Link]
package [Link].lab_j15;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];

public class MyDBClass extends SQLiteOpenHelper {


private static final String DBName = "LabDB";
private static final int DB_VERSION = 1;
Context context;
public MyDBClass(@Nullable Context context) {
super(context, DBName, null, DB_VERSION);
[Link] = context;
}

@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) {

public void addRecord(String name, String duration, String description) {

SQLiteDatabase database = [Link]();


ContentValues values = new ContentValues();
[Link]("name", name);
[Link]("duration", duration);
[Link]("description", description);

[Link]("course", null, values);


[Link](context, "Added successfully",
Toast.LENGTH_SHORT).show();
// [Link]();
}

public ArrayList<CourseModel> getRecords() {


SQLiteDatabase db = [Link]();

Cursor cursor = [Link]("SELECT * FROM course", null);

ArrayList<CourseModel> recordList = new ArrayList<>();

while ([Link]()) {

CourseModel model = new CourseModel();

[Link] = [Link](0);
[Link] = [Link](1);
[Link] = [Link](2);
[Link] = [Link](3);

[Link](model);
}
return recordList;
}

public void updateRecord(String duration, String name) {

SQLiteDatabase db = [Link]();

ContentValues cv = new ContentValues();


[Link]("duration", duration);

[Link]("course", cv, "name=?", new String[]{name});


[Link](context, "Updated successfully",
Toast.LENGTH_SHORT).show();
}

public void deleteRecord(String courseName) {


SQLiteDatabase database = [Link]();

[Link]("course", "name=?", new String[]{courseName});


[Link](context, "Deleted successfully",
Toast.LENGTH_SHORT).show();
}
}
11. Demonstrate Array Adapter using List View to display list of fruits.

[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];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

ListView lstView = findViewById([Link]);

String fruits[] = {"Apple","Banana","Orange","Mango","Dragan"};

ArrayAdapter adapter = new ArrayAdapter([Link],


[Link].simple_list_item_1,fruits);

[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

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


<TableLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">

<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];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

EditText username, password;


AppCompatButton loginBtn;

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();
}
});
}
}

6. Write an android code to make phone call using Intent

[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;

//6. Write an android code to make phone call using Intent

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

EditText mobNo = findViewById([Link]);


AppCompatButton callBtn = findViewById([Link]);

[Link](view -> {
Intent intent = new Intent(Intent.ACTION_CALL);
[Link]([Link]("[Link] + [Link]().toString()));
startActivity(intent);
});
}
}

7. Write an android code to turn ON/OFF Bluetooth

[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;

//7. Write an android code to turn ON/OFF Bluetooth

import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

AppCompatButton onBtn, offBtn;

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]();
}
}
});
}
}

8. Write an android code to turn ON /OFF the Wi-Fi


[Link]
<uses-permission
android:name="[Link].ACCESS_WIFI_STATE"/>
<uses-permission
android:name="[Link].CHANGE_WIFI_STATE"/>

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;

//8. Write an android code to turn ON /OFF the Wi-Fi

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

AppCompatButton onBtn, offBtn;

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);
}
});
}
}

You might also like