0% found this document useful (0 votes)
13 views23 pages

2022 Summer Finall

The document outlines the model answer scheme for the Summer 2022 examination in Mobile Application Development by the Maharashtra State Board of Technical Education. It provides instructions for examiners on assessing candidates' answers based on understanding rather than exact wording, and includes a series of questions with model answers related to Android features, architecture, and programming concepts. The document emphasizes the importance of flexibility in grading, particularly for programming and language use in responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views23 pages

2022 Summer Finall

The document outlines the model answer scheme for the Summer 2022 examination in Mobile Application Development by the Maharashtra State Board of Technical Education. It provides instructions for examiners on assessing candidates' answers based on understanding rather than exact wording, and includes a series of questions with model answers related to Android features, architecture, and programming concepts. The document emphasizes the importance of flexibility in grading, particularly for programming and language use in responses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
SUMMER – 2022 EXAMINATION
Subject Name: Mobile Application Development Model Answer Subject Code: 22617
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The figures
drawn by candidate and model answer may vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may vary and
there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based on
candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual (English +
Marathi) medium is introduced at first year of AICTE diploma Programme from academic year 2021-2022. Hence if
the students in first year (first and second semesters) write answers in Marathi or bilingual language (English
+Marathi), the Examiner shall consider the same and assess the answer based on matching of concepts with
model answer.

Q. Sub Answer Marking


No. Q. N. Scheme
Note: As Android programs contain many of the generated code statements from IDE,
while assessing such answers correct logical steps taken to obtain the required output
can be considered.
1 Attempt any FIVE of the following: 10 M
a) List any four features of Android operating system. 2M
Ans Features of Android Operating System: (Any four, ½
1)Storage M for one
2) Multitasking feature)
3) Web Browser
4) Open Source
5)Accessibility
6)Media Support
7)Streaming Media Support
8)Voice Based Features
9)Multitouch
10)External Storage
11) Video Calling
12) Handset Layout
13) Google cloud Messaging
14) WiFi Direct
b) Define Dalvik Virtual Machine (DVM). 2M

Page No: 1 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
Ans Dalvik Virtual Machine is a register-based machine that compiles byte code to get dex (Correct
code and that ensures that a device can run multiple instances efficiently. definition
2 M)
c) List any four folders from directory structure of Android project and 2M
elaborate in one line.
Ans Folders from directory structure: (List of
1) app: The App folder contains three subfolders (manifests, java and res) that make up names of
our application. any four
They are divided so that it should be fairly easy to determine which resources go in which folders : 1 M
folder. and
2) Manifest: This is where we would put our manifest files. Most Android apps have elaboration
single manifest file. But an app may have several manifest files due to application
in one line
versioning, or for supporting specific hardware.
3) Java: This is the folder in our project where we will be storing all of the source code
:1 M)
files written in Java programming language.
4) res: It contains folders that help us to separate and sort the resources of our application.
Resources
basically mean all the needed files except the source code.
5) drawable: The drawable folder contains graphics that can be drawn to the screen.
6) layout: The layout folder contains XML files used for your layouts. These file are used
to set up the layout for your Activity and is used for basic alignment of your layouts,
components, widgets, and similar
resources that are used for the UI of your application.
7) mipmap : The mipmap folder contains the launcher icon files for the app. A launcher
icon is a graphic that
represents your app to users.
8) values: The values folder contains XML files that contain simple values, such as
strings, integers, and colors.
The values folder is used to keep track of the values we will be using in our application.

d) List any four attributes of check box. 2M

Ans 1)id (Any four


2)checked attribute, ½
3)gravity M for each)
4)text
5) text color
6) text size
7) text style
8) background
9)padding
e) Draw diagram of activity life cycle. 2M

Page No: 2 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
Ans (2 M for
correct
diagram)

Page No: 3 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
ranges from 0 to 21.

OR

c) In any normal activity, ZoomControl can be displayed as component by following


syntax :
ZoomControl zoomControls = (ZoomControls) findViewById(R.id.simpleZoomControl);
zoomControls.show()
g) Name two classes used to play audio and video in Android. 2M

Ans 1) MediaPlayer (Any two


class names
2) MediaController 1 M each)

3) AudioManager

2. Attempt any THREE of the following: 12 M


a) Describe Android architecture with diagram. 4M

Page No: 4 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
Ans Diagram: 2M
Explanation:
2M

Android Architecture (Layer-wise Explanation)


1. Applications

This is the topmost layer of the Android architecture. It includes built-in native apps like Contacts,
Email, Gallery, Clock, and Music, as well as third-party apps such as games and tools that users
install. All applications run within the Android Runtime (ART or Dalvik) and use the services and
classes provided by the Application Framework.

2. Application Framework

The Application Framework provides all the essential classes and services needed to build Android
Page No: 5 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

applications. It manages hardware access, UI elements, and system resources. Core services in this
layer include the Activity Manager (for app lifecycle), View System (for UI components), Location
Manager (for GPS), Notification Manager (for status bar alerts), as well as services like Package
Manager, NFC service, and Telephony Manager.

3. Android Runtime

The Android Runtime layer is crucial and includes two main parts:
(i) Dalvik Virtual Machine (DVM) – It is a register-based virtual machine optimized for low
memory and CPU usage. It allows multiple apps to run efficiently and relies on the Linux Kernel for
memory and threading.
(ii) Core Libraries – These libraries provide Java-like functionalities that allow Android apps to be
written in Java. Android Runtime supports the Application Framework by offering all the core
features needed to run apps.

4. Platform Libraries

This layer contains various C, C++, and Java libraries used by Android apps and the Android
system. These libraries include libc (standard C library), SSL (for secure internet connections),
SQLite (for local database support), and other important libraries like Media, WebKit, OpenGL,
Surface Manager, and Graphics. These libraries help the Android Runtime and Framework to
perform tasks like graphics rendering, web access, media playback, and data storage.

5. Linux Kernel

The Linux Kernel is the bottom layer of the Android architecture and acts as the core of the
operating system. It provides a bridge between the hardware and software layers. The kernel
manages device drivers for display, camera, audio, memory, Bluetooth, and more. It is responsible
for important system functions like power management, memory handling, process control, device
management, and system security.

Page No: 6 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

b) Differentiate between DVM and JVM. 4M


Ans Any 4 points
of
DVM (Dalvik Virtual Machine) JVM (Java Virtual Machine) differences :
It is Register based which is designed to run It is Stack based. 1 M each
on low memory.
DVM uses its own byte code and runs the JVM uses java byte code and runs
“.Dex” file. From Android 2.2 SDK Dalvik “.class” file having JIT (Just In Time).
has got a Just in Time compiler
DVM has been designed so that a device A single instance of JVM is shared
can run multiple instances of the VM with multiple applications.
efficiently. Applications are given their own
instance.
DVM supports the Android operating JVM supports multiple operating
system only. systems.
There is a constant pool for every It has a constant pool for every
class. application.
Here the executable is APK. Here the executable is JAR.

d) Describe with example, how to create a simple database in SQLite (Assume 4M


suitable data).
(Note : Any other method such as creating subclass of SQLiteOpenHelper class
and overriding and using required methods with relevant example can also be
considered)
Ans This procedure is by openOrCreateDatabase() Description 1
1. The package imported into the application is android.database.sqlite.SQLiteDatabase. M, 1 M for
2. Here the class used is SQLiteDatabase. XML file , 2
3. The method used to create the database or connect to the database M for Java
is openOrCreateDatabse() method. File)
Program:
package com.example.myapp;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


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

SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);


db.execSQL("CREATE TABLE IF NOT EXISTS mytable(id INTEGER PRIMARY
Page No: 7 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
KEY, name TEXT);");
}
}

b. (Syntax of
State syntax to create Text View and Image button with any two attributes of each. TextView
Ans ..Text View: and
Syntax : ImageButton
<TextView : 1 M each Any
android:id="@+id/textView1" two appropriate
android:layout_width="<width value>” attributes of
android:layout_height="<height_value>" each : 1/2 M
android:text="<text to be displayed>"/> each)
Attributes/Properties of TextView:
● id: Supply an identifier name of this view, to later retrieve it with
View.findViewByID() or Activity.findViewById()
text: text attribute is used to set the text in a text view. We can set the text in xml as
well as in the java class.
● textColor: textColor attribute is used to set the text color of a text view. Color
value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
● textSize: textSize attribute is used to set the size of text of a text view. We can set
the text size in sp(scale independent pixel) or dp(density pixel).
● textStyle: textStyle attribute is used to set the text style of a text view. The possible
text styles are bold, italic and normal. If we need to use two or more styles for a text
view then “|” operator is used for that.

ImageButton:
Syntax :
<ImageButton
android:id="@+id/imageButton"
android:layout_width="<width value>"
android:layout_height="<height value>"
app:srcCompat="<image source from drawable folder "/>
Attributes/Properties of ImageButton:

● id: id is an attribute used to uniquely identify a image button. Below is


the example code in which we set the id of a image button.
● src: src is an attribute used to set a source file of image or you can say image in
your image button to make your layout look attractive.
● background: background attribute is used to set the background of an image
button. We can set a color or a drawable in the background of a Button.
● padding: padding attribute is used to set the padding from left, right, top
or bottom of the ImageButton.
c) 4M

Page No: 8 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

d) State and elaborate the syntax of required class and methods for 4M
Geocoding.
Ans (2 M for
The Geocoder class in Android is used to perform geocoding and reverse geocoding.
explanation
Geocoding is the process of converting a location name or street address into geographic and syntax
coordinates such as latitude and longitude. of class, 2 M
for
Reverse geocoding is the opposite, where coordinates are converted into a readable address. The
explanation
amount of address detail returned may vary; it can include full street information or just city and
and syntax
postal code.
of any two
The Geocoder class requires a backend service which is not always available in all Android methods)
devices. If the backend service is missing, the geocoding methods will return an empty list. To
check if the service is present, the isPresent() method can be used.

Page No: 9 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
Syntax
1,Geocoder geocoder = new Geocoder(Context context);

Creates a Geocoder using the default locale.

2.Geocoder geocoder = new Geocoder(Context context, Locale locale);

Creates a Geocoder using a specific locale (like Locale.US, Locale.FRANCE)..

a.

Page No: 10 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

public static boolean isPresent ()

Returns true if there is a geocoder implementation present that may return results. If true,
there is still no guarantee that any individual geocoding attempt will succeed.

4. Attempt any THREE of the following: 12 M


a) Explain with example, code to create GUI using absolute layout (Assume 4M
suitable data).

Ans AbsoluteLayout is a type of layout in Android that lets you place UI elements at exact x and y (Explanation
positions on the screen. Each view is positioned using fixed coordinates. However, this layout is not 2 M,
recommended because it creates a rigid and hard-to-maintain UI. If we want to add or move any
element, we must manually adjust the position of all other elements. Due to this inflexibility,
Example 2
AbsoluteLayout is now deprecated in Android. M)

activity_main.xml

<AbsoluteLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_x="10px"
android:layout_y="10px"
android:text="User Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="50px"
android:layout_y="50px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
</AbsoluteLayout>

Page No: 11 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

Write a program to demonstrate Date and Time picker.

✅ activity_main.xml (2 Marks)
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">

<Button
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date" />

<Button
android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Time"
android:layout_marginTop="10dp" />

</LinearLayout>

✅ MainActivity.java (3 Marks)
java
CopyEdit
package com.example.datetimepicker;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import java.util.Calendar;

public class MainActivity extends Activity {


Button btnDate, btnTime;

Page No: 12 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnDate = findViewById(R.id.btnDate);
btnTime = findViewById(R.id.btnTime);

btnDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Calendar c = Calendar.getInstance();
DatePickerDialog dp = new
DatePickerDialog(MainActivity.this,
null, c.get(Calendar.YEAR), c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH));
dp.show();
}
});

btnTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Calendar c = Calendar.getInstance();
TimePickerDialog tp = new
TimePickerDialog(MainActivity.this,
null, c.get(Calendar.HOUR_OF_DAY),
c.get(Calendar.MINUTE), false);
tp.show();
}
});
}
}

Discuss developer console with at least four features (pt2 paper me hai)
● Google Play Developer Console is the platform that Google provides for Google
Play and Android developers to publish their apps.
● The Google Play Developer console allows app developers and marketers to
better understand how their apps are performing in terms of growth, technical
performance such as crashes or display issues, and financials.
● The console offers acquisition reports and detailed analysis which can help app
devs find out how well an app is really performing.
● The platform is important as it provides developers with access to first party data
(trustworthy information collected about an app’s audience that comes straight
from Google Play) that highlights the real performance of an app.
It shows the number of impressions an app listing receives and the number of
Installs an app receives from different sources over time.

Page No: 13 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

d) 4M
Ans 4M
● (Any 4
relevant
features 1M
each )

Page No: 14 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

Page No: 15 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
5. Attempt any TWO of the following: 12 M
a) Write a program to convert temperature from celcius to farenhite and vice versa 6M
using Toggle button. (Design UI as per your choice. Write XML and java file)
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
Ans Java XML file:
package com.example.tempconverter; 2M
import android.os.Bundle;
import android.view.View;
import android.widget.*; Java Code:
import androidx.appcompat.app.AppCompatActivity; 4M
public class MainActivity extends AppCompatActivity {

EditText inputTemp;
ToggleButton toggle;
TextView result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

inputTemp = findViewById(R.id.inputTemp);
toggle = findViewById(R.id.toggle);
result = findViewById(R.id.result);

toggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String value = inputTemp.getText().toString();
if (!value.isEmpty()) {
double temp = Double.parseDouble(value);
if (toggle.isChecked()) {
// Convert Celsius to Fahrenheit
double f = (temp * 9 / 5) + 32;
result.setText("Fahrenheit: " + f);
} else {
// Convert Fahrenheit to Celsius
double c = (temp - 32) * 5 / 9;
result.setText("Celsius: " + c);
}
} else {
result.setText("Enter Temperature");
}
}
});
}
}

Xml
<?xml version="1.0" encoding="utf-8"?>
Page No: 16 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
android:id="@+id/inputTemp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter temperature"
android:inputType="numberDecimal" />

<ToggleButton
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="C to F"
android:textOff="F to C" />

<TextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="Result here" />
</LinearLayout>

Page No: 17 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

Page No: 18 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________

b) Write a program to capture an image using camera and display it. 6M


(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
Ans ✅ Corrected Full Code: XML file:
2M
java
CopyEdit
package com.tutlane.cameraexample;
Java Code:
import android.content.Intent; 4M
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ImageView img;
Button btn;
int code = 1;

protected void onCreate(Bundle b) {


super.onCreate(b);
setContentView(R.layout.activity_main);

img = findViewById(R.id.capturedImage);
btn = findViewById(R.id.btnTakePicture);

btn.setOnClickListener(v -> {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, code);
});
}

@Override
protected void onActivityResult(int req, int res, Intent data) {
if (req == code && res == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(photo);
} else if (res == RESULT_CANCELED) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
}
}
}
xml
CopyEdit
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"

Page No: 19 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
android:paddingRight="10dp">

<Button
android:id="@+id/btnTakePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take a Photo"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />

<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/capturedImage"
android:layout_above="@+id/btnTakePicture"/>
</RelativeLayout>

Page No: 20 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
6. Attempt any TWO of the following: 12 M
a) Write a program to implement Android Activity Life Cycle. Use toast messages 6M
to display message through life cycle.
(Note: No XML code is required. In java file all imports are not expected.)
Ans package com.example.p1; Use of any 6
import androidx.appcompat.app.AppCompatActivity; methods of
import android.os.Bundle; Activity life
import android.widget.Toast; cycle : 1 M
public class MainActivity extends AppCompatActivity { each
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(),"Activity
created",Toast.LENGTH_LONG).show();
}

@Override
protected void onStart() {
super.onStart();
Toast.makeText(getApplicationContext(),"Activity
Started",Toast.LENGTH_LONG).show();
}

@Override
protected void onStop() {
super.onStop();
Toast.makeText(getApplicationContext(),"Activity
Stop",Toast.LENGTH_LONG).show();
}

@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"Activity
Destroy",Toast.LENGTH_LONG).show();
}

@Override
protected void onPause() {
super.onPause();
Toast.makeText(getApplicationContext(),"Activity
Pause",Toast.LENGTH_LONG).show();
}
@Override
protected void onRestart()
{ super.onRestart ();
Page No: 21 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
Toast.makeText(getApplicationContext(),"Activity
Restart",Toast.LENGTH_LONG).show();
}

@Override
protected void onResume() {
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Resume",Toast.LENGTH_LONG).show();
}
}

Design UI using table layout to display buttons with 0 9 numbers on it. Even
display submit and clear button. When user clicks on particular buttons and later
when clicks on submit button, it should display the numbers clicked
package com.example.tableinput;

import android.os.Bundle;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

String input = "";


int[] ids = { R.id.b0, R.id.b1, R.id.b2, R.id.b3, R.id.b4,
R.id.b5, R.id.b6, R.id.b7, R.id.b8, R.id.b9 };

@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);

// Initialize submit and clear buttons before the loop


Button submit = findViewById(R.id.btnSubmit);
Button clear = findViewById(R.id.btnClear);

// Set the onClickListener for the Submit button


submit.setOnClickListener(v -> Toast.makeText(this, input, Toast.LENGTH_SHORT).show());

// Set the onClickListener for the Clear button


clear.setOnClickListener(v -> {
input = "";
Toast.makeText(this, input, Toast.LENGTH_SHORT).show();
});

// Initialize and set listeners for the number buttons (0-9) in a loop
for (int id : ids) {
Button btn = findViewById(id);

Page No: 22 | 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
_________
btn.setOnClickListener(v -> input += btn.getText().toString());
}
}
}

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


<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:padding="16dp">

<TableRow>
<Button android:id="@+id/b1" android:text="1" />
<Button android:id="@+id/b2" android:text="2" />
<Button android:id="@+id/b3" android:text="3" />
</TableRow>

<TableRow>
<Button android:id="@+id/b4" android:text="4" />
<Button android:id="@+id/b5" android:text="5" />
<Button android:id="@+id/b6" android:text="6" />
</TableRow>

<TableRow>
<Button android:id="@+id/b7" android:text="7" />
<Button android:id="@+id/b8" android:text="8" />
<Button android:id="@+id/b9" android:text="9" />
</TableRow>

<TableRow>
<Button android:id="@+id/b0" android:text="0" />
<Button android:id="@+id/btnClear" android:text="Clear" />
<Button android:id="@+id/btnSubmit" android:text="Submit" />
</TableRow>

</TableLayout>

Page No: 23 | 23

You might also like