Model Answer For Mobile Application Development (22617) - Summer 2024 Exam Model Answer For Mobile Application Development (22617) - Summer 2024 Exam
Model Answer For Mobile Application Development (22617) - Summer 2024 Exam Model Answer For Mobile Application Development (22617) - Summer 2024 Exam
Q. Su Answer Marking
No b Scheme
. Q.
N.
Page No: 1 | 34
2)viewgroups
3)fragments
4)activity
An 1. android:textOff any 2
s 2. android:textOn attributes ,
3. android:id one
4. android:checked attribute
5. android:gravity for one M
6. android:textColor
7. android:textSize
8. android: textStyle
e) Define service in android operating system. 2M
An A service is an application component which runs without direct interaction with the user in Correct
s the background. Services are used for repetitive and potentially long running operations, i.e., definition
Internet downloads, checking for new data, data processing, updating content providers and 2M
the like.
An getMyLocation(): This method returns the currently displayed user location. One
s method for
moveCamera(CameraUpdate update): This method reposition the camera according to the 1M
instructions defined in the update.
Page No: 2 | 34
An Android is a new generation mobile OS which runs on Linux kernel. There are some Any four
s following points which describe why we use Android OS: points,
1. Desktop: The Android phone adds widgets to the desktop. The purpose for the widget, 4M
for
example, the Facebook widget allows us to update our facebook desktop. The people widget
allows us to make possible different actions for different contacts right from our desktop.
The
message widget allows us to immediately see our e-mail from the desktop.
2. Connectivity: On one page/desktop we could be able to have four connecting device tool
button like, Turn ON/OFF Bluetooth, Turn ON/OFF WiFi, Turn ON/OFF mobile network,
Turn On/Off GPS and so on. These buttons let us switch ON/OFF instantly which will help
us to conserve battery life.
3. Browser: The Android OS browser is one of the best browsers on the mobile market. It
generally loads pages faster than Safari or any other browser, has Flash support and simply
does everything a browser should do. For example, iPhone has Safari browser. It is stable,
has no Flash support, so we cannot watch Youtube videos or any related contents, it is not
flexible but monopolistic.
4. Open to Carrier: If we know Java programming language then we are open to Android
world.
5. Market: Android OS has an android market. The android apps are free and work as well.
6. Future: The future mobile phones are basically going to be smart phones.
7. Muti-Notification: Android phones have multi-notification system. With android the app
have access to the notification system and call all report.
8. Google Integration: The Android has inbuilt google support. For examle, Google Map,
G-Mail etc.
10. Endless Personalization: The Android cell phone allows to configuration their mobile
to look and behave exactly like they want.
b) Compare JVM and DVM. (any four points) 4M
An Any four
s JVM DVM points 4
M, 1 M for
one point)
Page No: 3 | 34
JVM forms separate classes in separate DVM forms multiple class in .dex byte
code file.
.class byte code files.
The executable format of JVM is JAR. The executable format of DVM is APK.
JVM has different constant pools. DVM has common constant pool.
It runs .class byte code directly. The .class byte codes are optimized to
.odex format before executing in DVM.
An Android is a multi-process system, in which each application (and parts of the system) runs correct
s in its own process. explanatio
n4M
Most security between applications and the system is enforced at the process level through
standard Linux facilities, such as user and group IDs that are assigned to applications.
The Android security model is primarily based on a sandbox and permission mechanism.
Each application is running in a specific Dalvik virtual machine with a unique user ID
assigned to it, which means the application code runs in isolation from the code of all others
applications. As a consequence, one application has not granted access to other applications’
files.
Android application has been signed with a certificate with a private key Know the owner of
the application is unique.
When an application is installed in The phone is assigned a user ID, thus avoiding it from
affecting it Other applications by creating a sandbox for it. This user ID is permanent on
which devices and applications with the same user ID are allowed to run in a single process.
This is a way to ensure that a malicious application has Can not access / compromise the data
of the genuine application.
Page No: 4 | 34
The purpose of a permission is to protect the privacy of an Android user. Android apps must
request permission to access sensitive user data (such as contacts and SMS), as well as certain
system features (such as camera and internet).
Permissions are divided into several protection levels. The protection level affects whether
runtime permission requests are required.
Android introduced shared user ID & permission to allow application components talk to
each other & enable application to access to critical system in Android devices.
Page No: 5 | 34
onCreate (): Called then the activity is created. Used to initialize the activity, for example
create the user interface.
onResume (): Called if the activity get visible again and the user starts interacting with the
activity again. Used to initialize fields, register listeners, bind to services, etc.
onPause (): Called once another activity gets into the foreground. Always called before the
activity is not visible anymore. Used to release resources or save application data. For
Page No: 6 | 34
onStop (): Called once the activity is no longer visible. Time or CPU intensive shutdown
operations, such as writing information to a database should be down in the onStop() method.
This method is guaranteed to be called as of API 11.
1. Activity States:
The Android OS uses a priority queue to assist in managing activities running on the device.
Based on the state a particular Android activity is in, it will be assigned a certain priority
within the OS. This priority system helps Android identify activities that are no longer in
use, allowing the OS to reclaim memory and resources. Fig. illustrates the states an activity
can go through, during its lifetime:
These states are often broken into three main teams as follows:
1. Active or Running:
Activities are thought of active or running if they're within the foreground, additionally
referred to as the top of the activity stack. this can be thought of the highets priority activity
within the Android Activity stack, and as such only be killed by the OS in extreme things,
like if the activity tries to use more memory than is available on the device as this might
cause the UI to become unresponsive.
2. Paused:
When the device goes to sleep, or an activity continues to be visible but partially hidden by
a new, non-full-sized or clear activity, the activity is taken into account paused. Paused
activities are still alive, that is, they maintain all state and member information, and stay
attached to the window manager. This can be thought of to be the second highest priority
activity within the android Activity stack and, as such, can solely be killed by the OS if
killing this activity can satisfy the resource requirement needed to keep the Active/Running
Activity stable and responsive.
3. Stopped:
Activities that are utterly obscured by another activity are thought of stopped or within the
background. Stopped activities still try and retain their state and member info for as long as
possible but stopped activities are thought of to be loweat priority of the three states and, as
such, the OS can kill activities during this state initial to satisfy the resource needs of higher
priority activities.
Page No: 7 | 34
An ScrollView Explain:
s 1M
ScrollView is used to scroll the child elements of palette inside ScrollView. Android
supports vertical scroll view as default scroll view. Vertical ScrollView scrolls elements Attributes:
vertically.Android uses HorizontalScrollView for horizontal ScrollView. 1M
Example :
Attributes of ScrollView 2M
• android:fillViewport - Defines whether the scrollview should stretch its content to
fill the viewport.
• android:scrollbars - scrollbars attribute is used to show the scrollbars in horizontal
or vertical direction
• android:layout_width – Define the width
• android:layout_height – Define height
• android:id – Define id
Page No: 8 | 34
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 2"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 3"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 4"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Page No: 9 | 34
An Google Play Developer Console is the platform that Google provides for Google Play and Any 4
s Android developers to publish their apps. points :
4M
● 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: 10 | 34
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnStartService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:id="@+id/btnStopService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="Button 2"/>
</LinearLayout>
2. Frame Layout
FrameLayout is designed to block out an area on the screen to display a single item.
Generally, FrameLayout should be used to hold a single child view, because it can be difficult
Page No: 11 | 34
We can add multiple children to a FrameLayout and control their position within the
FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.
Example:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/table"
android:foregroundGravity="center"
android:foreground="#000"
tools:context=".MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="10dp"
android:src="@mipmap/ic_launcher"
android:scaleType="centerCrop" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity=""
android:text="CENTER"/>
</FrameLayout>
Page No: 12 | 34
<AutoCompleteTextView
android:id="@+id/txt"
android:textSize="50dp"
android:layout_centerHorizontal="true"
android:hint="Enter Text to search"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
package com.example.al_libaansapp;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
Page No: 13 | 34
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = findViewById(R.id.txt);
An • Android Fragment is the part of activity, it is also known as sub-activity. There can Define
s Fragment :
be more than one fragment in an activity.
2M
Page No: 14 | 34
• We can only show a single Activity on the screen at one given point of time so we
were not able to divide the screen and control different parts separately. With the
help of Fragment’s we can divide the screens in different parts and controls
different parts separately.
Example:
activity_main.xml:
<fragment
android:id="@+id/Frag1"
android:layout_width="match_parent"
android:layout_height="400dp"
android:name="com.example.al_libaansapp"/>
<fragment
android:id="@+id/Frag2"
android:layout_width="match_parent"
android:layout_height="400dp"
android:name="com.example.al_libaansapp"/>
</LinearLayout>
- Fragment1.xml:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Fragment 1"
android:textSize="40dp"
android:textColor="@color/white"
android:textStyle="bold" />
</FrameLayout>
- Fragment2.xml:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/purple"
tools:context=".Fragment2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Fragment 2"
android:textSize="40dp"
android:textStyle="bold"
android:textColor="@color/black"/>
</FrameLayout>
Page No: 16 | 34
1. Install-time permissions
• Install-time permissions give your app limited access to restricted data, and they
allow your app to perform restricted actions that minimally affect the system or
other apps.
• When you declare install-time permissions in your app, the system automatically
grants your app the permissions when the user installs your app.
a) Normal permissions
• These permissions allow access to data and actions that extend beyond your app's
sandbox.
• However, the data and actions present very little risk to the user's privacy, and the
operation of other apps.
b) Signature permissions
• If the app declares a signature permission that another app has defined, and if the
two apps are signed by the same certificate, then the system grants the permission
to the first app at install time. Otherwise, that first app cannot be granted the
permission.
2. Runtime permissions
• Many runtime permissions access private user data, a special type of restricted data
that includes potentially sensitive information. Examples of private user data
include location and contact information.
3. Special permissions
Page No: 17 | 34
Additionally, the platform and OEMs usually define special permissions when they want to
protect access to particularly powerful actions, such as drawing over other apps.
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
Page No: 18 | 34
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
Page No: 19 | 34
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
EditText et1,et2;
Button b1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEND_SMS)!
=
PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(MainActivity.this,new
Page No: 20 | 34
b1.setOnClickListener(new View.OnClickListener() {
@Override
try {
String msg=et2.getText().toString();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
catch(Exception e)
});
a) Develop android application to enter one number and display factorial of a number 6M
once click on button.
An (Note: Consider the appropriate XML file. All attributes are not required. xml file-
s In java file all imports are not expected. Different relevant logic/code can be 2M
considered.)
java code-
activity_main.xml 4M
Page No: 21 | 34
<EditText
android:layout_width="wrap_content"
android:layout_height=" wrap_content "
android:hint="Enter a number"
android:id="@+id/number"
android:inputType="number"
android:textSize="30dp"
/>
<Button
android:layout_width=" wrap_content "
android:layout_height="wrap_content"
android:id="@+id/btn1"
android:layout_below="@id/number"
android:textSize="20dp"
android:text="Calculate Factorial"
/>
<TextView
android:layout_width="wrap_content"
Page No: 22 | 34
MainActivity.java
package com.example.factorial;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
Page No: 23 | 34
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String strnum;
strnum = number.getText().toString();
num = Integer.parseInt(strnum);
factorial(num);
}
});
}
private void factorial(int num) {
int i = 1;
factor = i;
while (i <= num) {
factor = factor * i;
i++;
}
s = ”Factorial of Number is : ”+ factor;
tv.setText(s);
}
}
An (Note: Consider the appropriate XML file. All attributes are not required. XML file-
s In java file all imports are not expected. Different relevant logic/code can be 2M
considered.)
Java code-
4M
Page No: 24 | 34
Page No: 25 | 34
MainActivity.java
package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap; import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button b1;
ImageView imageView;
int CAMERA_REQUEST=1;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
b1=findViewById(R.id.photo); imageView=findViewById(R.id.image);
b1.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,CAMERA_REQUEST); } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) { super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_REQUEST) { Bitmap image= (Bitmap)
data.getExtras().get("data");
imageView.setImageBitmap(image); } } }
Page No: 26 | 34
An (Note: Consider the appropriate XML file. All attributes are not required. In java file all XML file:
s imports are not expected.) 1M
Java Code:
activity_main.xml 5M
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
MainActivity.Java
package com.example.location;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
public class MainActivity extends FragmentActivity implements
OnMapReadyCallback
{
Location currentlocation;
FusedLocationProviderClient fusedLocationProviderClient;
Page No: 27 | 34
An (Note: Consider the appropriate XML file. All attributes are not required. In java file Xml file-
s all imports are not expected. Different relevant logic/code can be considered.) 2M
Java code-
activity_main.xml 4M
</LinearLayout>
MainActivtiy.java
Package com.example.sensordisplay;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.view.View;
Page No: 29 | 34
An (Note: Consider the appropriate XML file. All attributes are not required. Xml file-
s Different relevant logic/code can be considered.) 2M
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />
Page No: 30 | 34
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>
MainActivity.java
package com.example.email;
import android.content.Intent;
Page No: 31 | 34
MainActivity.java
package com.example.checkbox;
import androidx.appcompat.app.AppCompatActivity;
import java.lang.StringBuffer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Page No: 33 | 34
Page No: 34 | 34