Android Programming QP Solutions 2017 - Tutorialsduniya
Android Programming QP Solutions 2017 - Tutorialsduniya
Semester : III
Max. Marks : 25
Website : https://www.tutorialsduniya.com
Section A (Compulsory)
m
Q1. (a) @string refers to a string in the .............. .xml file. [1 mark]
co
Ans: strings.xml file.
a.
Ans: Value starts from 0.
Ans: Android Package Kit is a collection of different files (like source code, images, icons,
audio, video etc.) compiled and bundled into one file for the distribution and installation
sD
purpose.
(f) What is the XML Tag used for Menu files ? [1 mark]
ri
(i) <main_menu>
to
(ii) <menu>
(iii) <menu_layout>
Tu
(g) Write the command used for installing a new application to the emulator or actual
connected device. [1 mark]
(i) The symbolic constant for Menu Key is KEYCODE_SET_MENU. True or False ? [1
mark]
Ans: False, the symbolic constant for Menu Key is KEYCODE_ MENU.
Ans: Honeycomb.
m
Section B (Attempt any three)
Q2. Explain the different states and methods of the Android Lifecycle stages with
co
diagram and example. [5 marks]
Ans: The different states and methods of the Android Lifecycle stages are as follows:
a.
1) onCreate(): This method fires when the system creates our activity. Our
implementation should initialize the essential components of our activity.
iy
2) onStart(): As onCreate() exits, the activity enters the Started state, and the activity
becomes visible to the user. This callback contains what amounts to the activity’s
un
final preparations for coming to the foreground and becoming interactive.
3) onResume(): The system invokes this callback just before the activity starts
sD
interacting with the user. At this point, the activity is at the top of the activity stack,
and captures all user input. Most of an app’s core functionality is implemented in the
onResume() method.
al
4) onPause(): The system calls onPause() when the activity loses focus and enters a
Paused state. This state occurs when, for example, the user taps the Back or Overlay
button. When the system calls onPause() for our activity, it technically means your
ri
activity is still partially visible, but is an indication that the user is leaving the activity.
to
5) onStop(): The system calls onStop() when the activity is no longer visible to the user.
This may happen because the activity is being destroyed, a new activity is starting, or
an existing activity is entering a Resumed state and is covering the stopped activity.
Tu
6) onRestart(): The system invokes this callback when an activity in the Stopped state is
about to restart. onRestart() restores the state of the activity from the time that it was
stopped.
7) onDestroy(): The system invokes this callback before an activity is destroyed. This
callback is the final one that the activity receives. onDestroy() is usually implemented
to ensure that all of an activity’s resources are released when the activity, or the
process containing it, is destroyed.
m
co
a.
iy
un
lsD
r ia
to
Tu
Q3. What are Intents and Intent filters ? How many types of Intents are there in
Android system ? How is intent built ? Explain with example. [5 marks]
Ans: Intent is a messaging object that we can use to request an action from another app
component.
Intent filter is an expression in an app's manifest file that specifies the type of intents that the
component would like to receive.
There are 2 types of Intents in the Android system,
i.putExtra(“Key1”, “Tutorialsduniya”);
m
startActivity(i);
2. Implicit Intent: It does not name a specific component, but instead declare a general
co
action to perform, which allows a component from another app to handle it.
Example, if we want to show the user a location on a map, we can use an implicit intent to
request that another capable app show a specified location on a map.
a.
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(https://www.tutorialsduniya.com));
startActivity(i);
iy
un
Q4. What is method overriding in OOPs ? Can we make a class both final and abstract
at the same time ? Why ? [5 marks]
sD
Ans: If subclass (child class) has the same method as declared in the parent class, it is known
as method overriding in Java. In other words, if a subclass provides the specific
implementation of the method that has been declared by one of its parent class, it is known as
method overriding.
al
It is used to provide the specific implementation of a method which is already provided by its
superclass.
ri
Example:
to
class Vehicle{
obj.run();
}
No, we cannot make an abstract class final in Java because abstract and final are
the mutual exclusive concept. An abstract class is incomplete and can only be instantiated by
extending a concrete class and implementing all abstract methods, while a final class is
considered as complete and cannot be extended further. This means when you make an
abstract class final, it cannot be extended hence it cannot be used and that's why Java
compiler throws a compile time error when you try to make an abstract class final in Java.
m
Q5. Explain the types of Layout supported by android system. What is the difference
co
between Linear Layout and Relative Layout ? Give example. [5 marks]
Ans: Layout is the visual structure for a user interface, such as UI for an activity.
a.
There are 6 types of layouts supported by android system,
iy
a. Linear Layout: This layout is a viewgroup that aligns all children in a single direction,
vertically or horizontally.
un
b. Relative Layout: This layout is a viewgroup that displays all the child views in relative
positions.
c. Table Layout: This layout is a view that groups views into rows and columns.
sD
d. Absolute Layout: This layout enables us to specify exact location of its children.
This layout is a viewgroup that aligns all This layout is a viewgroup that displays all
children in a single direction, vertically or the child views in relative positions.
to
horizontally.
A vertical LinearLayout will only have one A RelativeLayout can have any number of
child per row and a horizontal LinearLayout elements in the row as well as in the column.
Tu
Q6. Explain how you can connect to SQLite database ? How can we load data from a
file to SQLite database ? [5 marks]
Ans: SQLite is a opensource SQL database that stores data to a text file on a device. Android
comes in with built in SQLite database implementation.
Example:
m
SQLiteDatabase TD = openOrCreateDatabase(“TutorialsDuniya”, MODE_PRIVATE, null);
We can load our data into the database by passing a ContentValues object to the
co
insert() method.
Example:
a.
SQLiteDatabase TD = mDbHelper.getWritableDatabase();
values.put(FeedEntry.COLUMN_NAME_TITLE, title); iy
un
values.put(FeedEntry.COLUMN_NAME_TITLE, subtitle);
know at [email protected]
to
Visit https://www.tutorialsduniya.com
Tu
DU Programs: https://www.tutorialsduniya.com/programs
TutorialsDuniya App: http://bit.ly/TutorialsDuniyaApp
C++ Tutorial: https://www.tutorialsduniya.com/cplusplus
Java Tutorial: https://www.tutorialsduniya.com/java
JavaScript Tutorial: https://www.tutorialsduniya.com/javascript
Python Tutorial: https://www.tutorialsduniya.com/python
Kotlin Tutorial: https://www.tutorialsduniya.com/kotlin
JSP Tutorial: https://www.tutorialsduniya.com/jsp