Sie sind auf Seite 1von 27

1. What is Android? Explain Application of Android?

What is Android :
o Android is a software package and linux based operating system for mobile
devices such as tablet computers and smartphones.

o It is developed by Google and later the OHA (Open Handset Alliance). Java
language is mainly used to write the android code even though other
languages can be used.

o The goal of android project is to create a successful real-world product that


improves the mobile experience for end users.

What is Open Handset Alliance (OHA)

o It's a consortium of 84 companies such as google, samsung, AKM,


synaptics, KDDI, Garmin, Teleca, Ebay, Intel etc.

o It was established on 5th November, 2007, led by Google. It is committed


to advance open standards, provide services and deploy handsets using the
Android Plateform

Features of Android

o After learning what is android, let's see the features of android. The
important features of android are given below:

1) It is open-source.
2) Anyone can customize the Android Platform.
3) There are a lot of mobile applications that can be chosen by the
consumer.
4) It provides many interesting features like weather details, opening
screen, live RSS (Really Simple Syndication) feeds etc.
o It provides support for messaging services(SMS and MMS), web browser,
storage (SQLite), connectivity (GSM, CDMA, Blue Tooth, Wi-Fi etc.), media,
handset layout etc.

Android applications

o Entertainment
o Tools
o Communication
o Productivity
o Personalization
o Music and Audio
o Social
o Media and Video
o Travel and Local etc.

2) How do you handle multiple resolution screens in android?

3) Difference between implicit intent and explicit intent?

4)What are the different storage available in Android?

The various storage provided by android are:

o Shared Preferences
o Internal Storage
o External Storage
o SQLite Databases
o Network Connection

Shared Preferences

o Android shared preference is used to store and retrieve primitive information.


In android, string, integer, long, number etc. are considered as primitive data
type.
Android Shared preferences are used to store data in key and value pair so that we
can retrieve the value on the basis of key.
It is widely used to get information from user such as in settings.
Internal Storage

Internal Storage is useful to store the data files locally on the device’s internal memory
using FileOutputStream object. After storing the data files in device internal storage, we can read
the data file from device using FileInputStream object.

External Storage

External Storage is useful to store the data files publically on the shared external storage
using FileOutputStream object. After storing the data files on external storage, we can read the data
file from external storage media using FileInputStream object.

The data files saved in external storage are word-readable and can be modified by the user when
they enable USB mass storage to transfer files on a computer.

SQLite Databases

In android applications Shared Preferences, Internal Storage and External Storage options are useful
to store and maintain the small amount of data. In case, if we want to deal with large amount of
data, then SQLite database is the preferable option to store and maintain the data in structured
format.

By default, Android comes with built-in SQLite Database support so we don’t need to do any
configurations.

Just like we save the files on device’s internal storage, Android stores our database in a private disk
space that’s associated to our application and the data is secure, because by default this area is not
accessible to other applications.

The package android.database.sqlite contains all the required API’s to use SQLite database in our
android applications.

Q Write Short Note on


1) Option Menu
o Android Option Menus are the primary menus of android. They can be used for settings,
search, delete item etc.
o Here, we are going to see two examples of option menus. First, the simple option menus and
second, options menus with images.
o Here, we are inflating the menu by calling the inflate() method of MenuInflater class. To
perform event handling on menu items, you need to override onOptionsItemSelected()
method of Activity class.
2) Context Menu

Context Menu is like a floating menu and that appears when the user performs a long press or click
on an element and it is useful to implement an actions that effect the selected content or context
frame.

The android Context Menu is more like the menu which displayed on right click in Windows or Linux.
It affects the selected content while doing action on it.
It doesn't support item shortcuts and icons.
3) Popup Menu
Android Popup Menu displays the menu below the anchor text if space is available otherwise above
the anchor text. It disappears if you click outside the popup menu.
The android Popup Menu provides an overflow style menu for actions that are related to specific
content.
The android.widget.PopupMenu is the direct subclass of java.lang.Object class.

Q ) What are the basic tools used to develop an Android App?

Q ) Explain in Details OHA (Open Handset Alliance)?

What is Open Handset Alliance (OHA)


o It's a consortium of 84 companies such as google, samsung, AKM, synaptics,
KDDI, Garmin, Teleca, Ebay, Intel etc.

o It was established on 5th November, 2007, led by Google. It is committed to


advance open standards, provide services and deploy handsets using the Android
Plateform

Q) Explain Toast in Android with Example?

Andorid Toast can be used to display information for the short period of time. A toast
contains message to be displayed quickly and disappears after sometime.

The android.widget.Toast class is the subclass of java.lang.Object class.

, Toast is a small popup notification which is used to display an information about the operation
which we performed in our app. The Toast will show the message for a small period of time and it
will disappear automatically after a timeout.
Create a Toast in Android
we can create a Toast by instantiating an android.widget.Toast object using makeText() method.
The makeText() method will take three parameters: application context, text message and the
duration for the toast. We can display the Toast notification by using show() method.

context It’s our application context.

message It’s our custom message which we want to show in Toast notification.

duration It is used to define the duration for notification to display on screen.

We have a two ways to define the Toast duration, either in LENGTH_SHORT or LENGTH_LONG to
display the toast notification for short or longer period of time.

Syntax :

Toast.makeText(context, "message", duration).show();

Example :

Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();

Example of Toast : -

MainActivity.java

package example.hello.com.toast;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

Toast.makeText(getApplicationContext(),"HelloTEAM",Toast.LENGTH_SHORT).show();

}
}

Q3

1) Explain types of Mobile Applications?

2)What is widget? Explain any five widgets?

3) What is Layout? Explain different types of Layout in Android?

What is Layout ?

Layout defines a visual structure of an Activity (or app widget). It may be


considered as a set of rules according to which controls (buttons, text fields, input
fields etc.) are placed on the View.

Layouts structure
User interface in Android apps is built using Layouts. Each Layout is a subclass
of ViewGroup class, which derives from View class, which is the basic UI building
block. View is the base class for buttons, text fields etc.
The six different layouts are

1. Linear Layout
2. Relative Layout
3. Table Layout
4. Grid View
5. Tab Layout
6. List View

1. Linear Layout

In a linear layout, like the name suggests, all the elements are displayed in a linear
fashion(below is an example of the linear layouts), either Horizontally or Vertically and this
behavior is set in android:orientation which is an attribute of the node LinearLayout.

Example of Vertical layout


<LinearLayout android:orientation="vertical"> .... </LinearLayout>
Example of Horizontal layout
<LinearLayout android:orientation="horizontal"> .... </LinearLayout>

2. Relative Layout
In a relative layout every element arranges itself relative to other elements or a parent
element.

, lets consider the layout defined below. The “Cancel” button is placed relatively, to the right
ofthe “Login” button parallely.

Example:-

<Button android:id="@+id/btnLogin" ..></Button>

<Button android:layout_toRightOf="@id/btnLogin"
android:layout_alignTop="@id/btnLogin" ..></Button>

RelativeLayout is very powerful. Consider that for building mobile apps’


interfaces these can be run on multiple devices with different screens’
resolutions. RelativeLayout allows (if properly built, of course) to adjust your set
of controls easily to almost every type of screen.

Table Layout
Table layouts in Android works in the same way HTML table layouts work. We can divide
your layouts into rows and columns.
TableLayout allows to group elements into rows and columns:

Grid View
GridView displays items in two-dimensional grid. This type of Layout is often
used on screens displaying photos or similar sets of “blocks” to click:

In android, Grid View is a ViewGroup which is used to display items in a two dimensional, scrollable
grid and grid items are automatically inserted to the gridview layout using a list adapter.

Generally, the adapter pulls data from a sources such as an array or database and converts each item
into a result view and that’s placed into the list.

Tab Layout
Tabbed layouts allow to introduce tabs in our Android application. Then, a single
Activity may contain several tabs and user can easily switch between them

List View
ListView allows to display a list of items. It may be used in multiple places,
from short lists of menu options to long list of emails or news feed. It
allows to easily and quickly present a list of items:

Q ) Explain AVD? Write down Steps to create AVD?

Android virtual device (AVD) is an emulator which is used to replicate the functionality of an android
phone, tablet, android wear or TV to test our android applications locally. By using AVD manager
interface in android studio we can setup android virtual device emulator to test our applications.

AVDs are essentially emulators that allow Android applications to be tested without
the necessity to install the application on a physical Android based device. An AVD
may be configured to emulate a variety of hardware features including options such
as screen size, memory capacity and the presence or otherwise of features such as
a camera, GPS navigation support or an accelerometer.

When launched, an AVD will appear as a window containing an emulated Android


device environment.

How to Create Virtual Device/Emulator in Android Studio:


Step 1: Firstly, Select Tools > Android > AVD Manager > Click the AVD Manager icon in
the toolbar. Another way to open the AVD Manager directly by the AVD icon in the Tool
bar.
Step 2: Android Virtual Device Manager will be opened. After that Click on Create Virtual
Device.

Step 3: After that choose the Category, phone size and choose the pixels according to
your requirement. After this click on Next button.

Step 4: After that choose the SDK Version and Click on Next button. If you have various
SDK Versions like Kitkat, Lolipop and Marshmallow etc in your SDK then you can select
one of them. Here we have only Marshmallow SDK Version. So, we can go with the
Marshmallow SDK Version. Click on the next.

Step 5: After that Enter the AVD Name in Android Virtual Device and Click on Finish
button. Here you can do customization to AVD which you are creating as per your
requirement.

Click Finish and new AVD is created

Q 4 Write Short note on:


1) Symbian
o Symbian grew out of the Psion EPOC operating system.
Originally developed by Symbian Ltd – a joint venture of Psion,
Ericsson, Motorola and Nokia – the operating system was almost
ubiquitous. In 2009 250 millions devices were running Symbian.
It was Nokia that really drove the development of Symbian OS.
The S50 platform was used on nearly all Nokia handsets as well
as some Samsung and LG Ones; The use of different fragmented
platforms (Sony Ericsson and Motorola used UIQ and there was
MOAP(S) FOR NIT DoCoMo ) each with its own API , meant that
there were a variety of development techniques and no standard
market place for apps. The incompatibility of apps across
platforms and the failure to fully move to open source (several
key components were licensed from third parties) are probably
what sounded the death-knell for Symbian. Symbian, once the
largest codebase ever moved to Open Source, is now licence -only
and Nokia’s development of the OS has been outsourced to
Accenture.

2) J2Me
Designed for embedded System and mobile platform . Java ME
technology was originally created in order to deal with the constraint
associated with building application for small devices. For this
purpose Oracle defined the basics for Java ME Technology to fit such a
limited environment and make it possible to create Java Application
running on small devices with limited memory display and power
capacity . Java ME is an Open source implementation , Mika VM
,which contains the class libraries for implementing the Connected
Device Configuration .

Q) Explain Structure of Android Program?

Q) Explain in details Services and Intent Services

Android service is a component that is used to perform operations on the


background such as playing music, handle network transactions, interacting content
providers etc. It doesn't has any UI (user interface).

The service runs in the background indefinitely even if application is destroyed.

Moreover, service can be bounded by a component to perform interactivity and inter


process communication (IPC).
The android.app.Service is subclass of ContextWrapper class.

There can be two forms of a service.The lifecycle of service can follow two different paths:
started or bound.

1. Started
2. Bound

1) Started Service

A service is started when component (like activity) calls startService() method, now it
runs in the background indefinitely. It is stopped by stopService() method. The service
can stop itself by calling the stopSelf() method.

2) Bound Service

A service is bound when another component (e.g. client) calls bindService() method. The
client can unbind the service by calling the unbindService() method.

The service cannot be stopped until all clients unbind the service.
In android the application component such as an activity can start the service by
calling startService() which results in calling the service’s onStartCommand() method.

Start a Service
In android, the component such as an activity, service or receiver can start the service
using startService() method. Following is the sample code snippet of starting a service
using startService method.

Intent intent = new Intent(this, MyService.class);


startService(intent);
onBind()

The system will invoke this method when an another component wants to bind with the service by
calling bindService(). During implementation of this method, we must need to provide an interface
to the clients to communicate with the service by returning an IBinder object.
onCreate()
The system will invoke this method when the service is created initially
using onStartCommand() or onBind() methods to do one time setup procedures. In case, if the service
is already running, then this method will not call.
onDestroy()

The system will invoke this method when the service is no longer used and is being destroyed. This is
the final call that the service will receive and we need to implement this method in our service to
clean up any unused resources such as threads, receivers or listeners.

Q)Explain Life Cycle of Android Activity?


Android Activity Lifecycle :
Android Activity Lifecycle is controlled by 7 methods of android.app.Activity
class.
The android Activity is the subclass of ContextThemeWrapper class.
An activity is the single screen in android. It is like window or frame of Java.
By the help of activity, you can place all your UI components or widgets in a
single screen.
The 7 lifecycle method of Activity describes how activity will behave at different
states.

Android Activity Lifecycle methods Description


Method
onCreate called when activity is first created.
onStart called when activity is becoming
visible to the user.
onResume called when activity will start
interacting with the user.
onPause called when activity is not visible to
the user.
onStop called when activity is no longer
visible to the user.
onRestart called after your activity is stopped,
prior to start.
onDestroy called before the activity is
destroyed.
Q5
1) Explain various dialog boxes in Android?

Dialog is a small window that prompt messages to the user to make a decision or enter additional
details. Generally, the Dialogs are used with modals event and these useful to prompt users to
perform a particular action to proceed further in application.

AlertDialog This dialog is used to display prompt to the user with title, upto three buttons, list of selectable
items or a custom layout.

DatePickerDialog This dialog is a predefined UI control and it allow user to select Date.

TimePickerDialog It’s a predefined UI control and it allow user to select Time.

ProgressDialog This dialog box displays a progress wheel or progress bar. It is an extension of AlertDialog and suppo
adding buttons.

1) AlertDialog

Android AlertDialog can be used to display the dialog message with OK and Cancel
buttons. It can be used to interrupt and ask the user about his/her choice to continue or
discontinue.

Android AlertDialog is composed of three regions: title, content area and action buttons.

Android AlertDialog is the subclass of Dialog class.

setTitle() It is used to set the title of alertdialog and its an optional component.
setIcon() It is used to set the icon before the title

setMessage() It is used to set the message required message to display in alertdialog.

setCancelable() It is used to allow users to cancel alertdialog by clicking on outside of dialog area by setting tru
/ false.

setPositiveButton() It is used to set the positive button for alertdialog and we can implement click event of positive
button.

setNegativeButton() It is used to set the negative button for alertdialog and we can implement click event of negati
button.

2) ProgressBar
Progress bars are used to show progress of a task. For example, when
you are uploading or downloading something from the internet, it is
better to show the progress of download/upload to the user.
In android there is a class called ProgressDialog that allows you to
create progress bar.

ProgressDialog progress = new ProgressDialog(this);

By default the ProgressBar will be displayed as a spinning wheel, in case if we want to show it
like horizontal bar then we need to change the style property to horizontal
like style="?android:attr/progressBarStyleHorizontal".

android:id It is used to uniquely identify the control

android:minHeight It is used to set the height of progress bar.

android:minWidth It is used to set the width of progress bar.

android:max It is used to set the maximum value of progress bar.


android:progress It is used to set the default progress value between 0 and max. It must be an integer value.

3) DatePicker is a control which will allow users to select the date by day, month and year in our
application user interface.

If we use DatePicker in our application, it will ensure that the users will select a valid date.

in android DatePicker available in two modes, one is to show the complete calendar and another
one is to show the dates in spinner view.

It allows you to select date by day, month and year. Like DatePicker, android also provides
TimePicker to select time.

The android.widget.DatePicker is the subclass of FrameLayout class

android:id It is used to uniquely identify the control

android:datePickerMode It is used to specify datepicker mode either spinner or calendar

android:background It is used to set the background color for date picker.

android:padding It is used to set the padding for left, right, top or bottom of date picker

4)TimePicker

Android TimePicker widget is used to select date. It allows you to select time by hour and
minute. You cannot select time by seconds.

The android.widget.TimePicker is the subclass of FrameLayout class.

If we use TimePicker in our application, it will ensure that the users will select a valid time for the
day.

in android TimePicker available in two modes, one is to show the time in clock mode and another
one is to show the time in spinner mode.
We can change the TimePicker in spinner mode to AM / PM format instead of 24 Hours format by
using setIs24HourView(true) method in Activity file like as shown below.

TimePicker picker=(TimePicker)findViewById(R.id.timePicker1);
picker.setIs24HourView(true);

android:id It is used to uniquely identify the control

android:timePickerMode It is used to specify timepicker mode, either spinner or clock

android:background It is used to set the background color for date picker.

android:padding It is used to set the padding for left, right, top or bottom of date picker.

Q) Explain Dalvik Virtual Machine?

Dalvik Virtual Machine | DVM


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.

Let's see the compiling and packaging process from the source file:
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.

Q) Elaborate the Event Handling in Android?


Events are a useful way to collect data about a user's interaction
with interactive components of Applications.Like button presses or
screen touch etc. The Android framework maintains an event queue as
first-in, first-out (FIFO) basis. You can capture these events in your
program and take appropriate action as per requirements.

 Event Listeners − An event listener is an interface in the View class that


contains a single callback method. These methods will be called by the Android
framework when the View to which the listener has been registered is triggered
by user interaction with the item in the UI.

 Event Listeners Registration − Event Registration is the process by which an


Event Handler gets registered with an Event Listener so that the handler is
called when the Event Listener fires the event.
 Event Handlers − When an event happens and we have registered an event
listener for the event, the event listener calls the Event Handlers, which is the
method that actually handles the event

OnClickListener()

This is called when the user either clicks or touches or


onClick()
focuses upon any widget like button, text, image etc.
You will use onClick() event handler to handle such
event.

OnFocusChangeListener()

This is called when the widget looses its focus ie.


onFocusChange()
user goes away from the view item. You will use
onFocusChange() event handler to handle such
event.

OnTouchListener()

onTouch() This is called when the user presses the key, releases
the key, or any movement gesture on the screen. You
will use onTouch() event handler to handle such event.

OnMenuItemClickListener()

This is called when the user selects a menu item. You


onMenuItemClick()
will use onMenuItemClick() event handler to handle
such event.

onCreateContextMenuItemListener()

This is called when the context menu is being built(as


onCreateContextMenu()
the result of a sustained "long click)

onKey() OnFocusChangeListener()
This is called when the user is focused on the
item and presses or releases a hardware key on
the device. You will use onKey() event handler to
handle such event.

There are many more event listeners available as a part of View class like
OnHoverListener, OnDragListener etc

Event Listeners Registration


Event Registration is the process by which an Event Handler gets registered
with an Event Listener so that the handler is called when the Event Listener
fires the event. Though there are several tricky ways to register your event
listener for any event, but I'm going to list down only top 3 ways, out of
which you can use any of them based on the situation.

 Using an Anonymous Inner Class

 Activity class implements the Listener interface.

 Using Layout file activity_main.xml to specify event handler directly.

Touch Mode
Users can interact with their devices by using hardware keys or buttons or
touching the screen.Touching the screen puts the device into touch mode.
The user can then interact with it by touching the on-screen virtual buttons,
images, etc.You can check if the device is in touch mode by calling the View
class’s isInTouchMode() method.

Focus
A view or widget is usually highlighted or displays a flashing cursor when
it’s in focus. This indicates that it’s ready to accept input from the user.

 isFocusable() − it returns true or false

 isFocusableInTouchMode() − checks to see if the view is focusable in touch


mode. (A view may be focusable when using a hardware key but not when the
device is in touch mode)
android:foucsUp="@=id/button_l"

onTouchEvent()
public boolean onTouchEvent(motionEvent event){

switch(event.getAction()){

case TOUCH_DOWN:

Toast.makeText(this,"you have clicked down Touch


button",Toast.LENTH_LONG).show();

break();

case TOUCH_UP:

Toast.makeText(this,"you have clicked up touch


button",Toast.LENTH_LONG).show();

break;

case TOUCH_MOVE:

Toast.makeText(this,"you have clicked move touch


button"Toast.LENTH_LONG).show();

break;

return super.onTouchEvent(event) ;

Q)Write a short note.


a) AndroidManifest.xml file

The AndroidManifest.xml file contains information of your package, including components


of the application such as activities, services, broadcast receivers, content providers etc.

It performs some other tasks also:

o It is responsible to protect the application to access any protected parts by


providing the permissions.
o It also declares the android api that the application is going to use.
o It lists the instrumentation classes. The instrumentation classes provides
profiling and other informations. These informations are removed just before the
application is published etc.

This is the required xml file for all the android application and located inside the root
directory.

Elements of the AndroidManifest.xml file

<manifest>

manifest is the root element of the AndroidManifest.xml file. It has package attribute that
describes the package name of the activity class.

<application>

application is the subelement of the manifest. It includes the namespace declaration. This
element contains several subelements that declares the application component such as
activity etc.

The commonly used attributes are of this element are icon, label, theme etc.

android:icon represents the icon for all the android application components.

android:label works as the default label for all the application components.

android:theme represents a common theme for all the android activities.

<activity>

activity is the subelement of application and represents an activity that must be defined in
the AndroidManifest.xml file. It has many attributes such as label, name, theme,
launchMode etc.

android:label represents a label i.e. displayed on the screen.

android:name represents a name for the activity class. It is required attribute.

<intent-filter>

intent-filter is the sub-element of activity that describes the type of intent to which
activity, service or broadcast receiver can respond to.
<action>

It adds an action for the intent-filter. The intent-filter must have at least one action
element.

<category>

It adds a category name to an intent-filter.

b) Screen Orientation

The screenOrientation is the attribute of activity element. The orientation of android


activity can be portrait, landscape, sensor, unspecified etc. You need to define it in the
AndroidManifest.xml file.

Syntax:

<activity android:name="package_name.Your_ActivityName"
android:screenOrientation="orirntation_type">
</activity>

Example:

<activity android:name=" example.javatpoint.com.screenorientation.MainActivity"


android:screenOrientation="portrait">
</activity>

<activity android:name=".SecondActivity"
android:screenOrientation="landscape">
</activity>

The common values for screenOrientation attribute are as follows:

Value Description

Unspecified It is the default value. In such case, system chooses the orientation.

Portrait taller not wider

Landscape wider not taller

Sensor orientation is determined by the device orientation sensor.


c) AAPT

Das könnte Ihnen auch gefallen