Mobile Application Development
Mobile Application Development
Android is a Linux based operating system it is designed primarily for touch screen mobile devices such as
smart phones and tablet computers. The operating system has developed a lot in last 15 years starting from
black and white phones to recent smart phones or mini computers. One of the most widely used mobile OS
these days is android. The android is software that was founded in Palo Alto of California in 2003.
The android is a powerful operating system and it supports large number of applications in Smartphone’s.
These applications are more comfortable and advanced for the users. The hardware that supports android
software is based on ARM architecture platform. The android is an open source operating system means that
it’s free and any one can use it. The android has got millions of apps available that can help you managing your
life one or other way and it is available low cost in market at that reasons android is very popular.
Q. What is activity:-
An Android activity is one screen of the Android app's user interface. In that way an Android activity is very similar to
windows in a desktop application. An Android app may contain one or more activities, meaning one or more screens.
Method Description
On Resume Called when activity will start interacting with the user.
Linux kernel:
The android uses the powerful Linux kernel and it supports wide range of hardware drivers. The kernel is the
heart of the operating system that manages input and output requests from software. This provides basic
system functionalities like process management, memory management, device management like camera,
keypad, display etc the kernel handles all the things. The Linux is really good at networking and it is not
necessary to interface it to the peripheral hardware. The kernel itself does not interact directly with the user but
rather interacts with the shell and other programs as well as with the hard ware devices on the system.
Libraries:
The on top of a Linux kennel there is a set of libraries including open source web browser such as web kit,
library lab. These libraries are used to play and record audio and video. The SQ lite is a data base which is
useful for storage and sharing of application data. The SSL libraries are responsible for internet security etc.
Android Runtime:
The android runtime provides a key component called Dalvik Virtual Machine which is a kind of java virtual
machine. It is specially designed and optimized for android. The Dalvik VM is the process virtual machine in the
android operating system. It is software that runs apps on android devices.
The Dalvik VM makes use of Linux core features like memory management and multithreading which is in a
java language. The Dalvik VM enables every android application to run it own process. The Dalvik VM
executes the files in the .dex format.
In Android, Fragment is a part of an activity which enables more modular activity design. It will not be wrong if we say
a fragment is a kind of sub-activity. It represents a behavior or a portion of user interface in an Activity. We can combine
multiple Fragments in Single Activity to build a multi panel UI and reuse a Fragment in multiple Activities. We always need to
embed Fragment in an activity and the fragment lifecycle is directly affected by the host activity’s lifecycle.
We can create Fragments by extending Fragment class or by inserting a Fragment into our Activity layout by declaring the
Fragment in the activity’s layout file, as a <fragment> element. We can manipulate each Fragment independently, such as add
or remove them. While performing Fragment Transaction we can add a Fragment into back stack that’s managed by the
Activity. Back stack allow us to reverse a Fragment transaction on pressing Back button of device. For Example if we replace a
Fragment and add it in back stack then on pressing the Back button on device it display the previous Fragment
Fragment coding:-
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
Intents are used generally for starting a new activity using startActivity().
Use of Intent
1. For Launching an Activity
2. To start a New Service
3. For Broadcasting Messages
4. To Display a list of contacts in List View
i.setAction(Intent.ACTION_SEND);
There are some other standard actions that intents can use for launching activities.
Explicit Intent
An explicit intent is an Intent where you explicitly define the component that needs
to be called by the Android System. An explicit intent is one that you can use to
launch a specific app component, such as a particular activity or service in your app.
Syntax:
An Intent object carries information that the Android system uses to determine which component to start (such as the
exact component name or component category that should receive the intent), plus information that the recipient
component uses in order to properly perform the action.
1. ACTION_MAIN
Use: Adds an action to an intent Filter.
2. ACTION_PICK
Syntax:
It is using for picking the image from CAMERA or GALLERY.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
3. ACTION_CHOOSER
Use: It is used for choosing the image from the gallery.
startActivity(next);
5. ACTION_CALL
Use: Placing and immediate phone call
String data = “tel : 651234567”;
startActivity(myActivity);
Permission Needed:
6. ACTION_SEND
Use: Sending Text content from one activity to other.
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType(“text/plain”);
startActivity(sendIntent);
7. ACTION_SENDTO
Use : Preparing an SMS. The text is supplied as an Extra element. The intent excepts
such as values to be called “sms_body”
startActivity(intent);
Q. what is view and view group in mobile application:-
Android View
The View is a base class for all UI components in android. For example, the EditText class is used to accept the input from users in android
apps, which is a subclass of View.
Following are the some of common View subclasses that will be used in android applications.
TextView
EditText
Button
CheckBox
RadioButton
ImageButton
Progress Bar
Spinner
Linear Layout
Relative Layout
Table Layout
Frame Layout
Web View
List View
Grid View
Both View and View Group subclasses together will play a key role to create a layout in android applications.
A layout defines the structure for a user interface in your app, such as in an activity. All elements in the layout are built using
a hierarchy of View and ViewGroup objects. A View usually draws something the user can see and interact with. Whereas
a ViewGroup is an invisible container that defines the layout structure for View and other ViewGroup objects
Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way
you create web pages in HTML — with a series of nested elements.
Each layout file must contain exactly one root element, which must be a View or ViewGroup object. Once you've defined the
root element, you can add additional layout objects or widgets as child elements to gradually build a View hierarchy that
defines your layout. For example, here's an XML layout that uses a vertical LinearLayout to hold a TextView and a Button
Q. Related layout in android:-
Android RelativeLayout enables you to specify how child views are positioned relative to each other. The position of each view can be
specified as relative to sibling elements or relative to the parent.
Relative Layout
RelativeLayout Attributes
Following are the important attributes specific to RelativeLayout −
Sr.No Attribute & Description
.
1
android:id
2
android:gravity
This specifies how an object should position its content, on both the X and Y axes. Possible
values are top, bottom, left, right, center, center_vertical, center_horizontal etc.
3
android:ignoreGravity
Positions the bottom edge of this view above the given anchor view ID and must be a
reference to another resource, in the form "@[+][package:]type:name"
5 android:layout_alignBottom
Makes the bottom edge of this view match the bottom edge of the given anchor view ID
and must be a reference to another resource, in the form "@[+][package:]type:name".
6 android:layout_alignParentBottom
If true, makes the bottom edge of this view match the bottom edge of the parent. Must
be a boolean value, either "true" or "false".
In Microsoft Word, highlighting a passage of text, holding down the Control key, and clicking the mouse
revealed a contextual menu that contained only commands related to the selected piece of data.
Displaying notification is one of the most important features in an Android app. Notification are short
messages which appear on home screen of the device. In this example you will learn how to
programatically create and display a Notification from your app which will work for all versions of
Android.
Before implementing it is important to understand what are various components in a Notification design
(later we can check how to implement each of them)
Below is the latest default design of an Android Notification . You can only define content of various
components in the design( You cannot change the UI design itself as it defined by system templates)
Courtesy: Google
Dev
1. Small Icon
2. App Name (Given by System)
3. Timestamp
4. Large Icon
5. Content Title
6. Content Text
Merely creating a notification object wont display it, to display the notification you will need to
call notify() on the NotificationManager object as shown below. As you can see a unique integer identifier
is also required while issuing the notification. This integer acts as a unique identifier for that particular
notification
In android, by using the ConnectivityManager class we can easily determine whether the device connected to the network/internet or not
and also we can determine the type of internet connection currently available i.e. whether it’s mobile data or Wi-Fi.
To get the internet connection status, our app must acquire the INTERNET and ACCESS_NETWORK_STATE permissions. For that, we need
to add the following permissions in the android manifest file like as shown below.
<manifest>
....
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
....
</manifest>
A web server, PHP programming language and the database MySQL. KSWEB allows you to organize a platform for
running and debugging Web applications (sites) in your Android device. ... To start the server it is enough to run our
application, select, if necessary, port and the root directory.
Steps to get location in Android
To access current location information through location providers, we need to set permissions with android
manifest file.
</manifest>
Q. which classes are provided by android framework to play audio and video in
android:-
Android provides many ways to control playback of audio/video files and streams. One
of this ways is through a class called Media Player.
Android is providing Media Player class to access built-in mediaplayer services like
playing audio,video e.t.c. In order to use MediaPlayer, we have to call a static
Method create() of this class. This method returns an instance of MediaPlayer class.
Its syntax is as follows −
MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.song);
The second parameter is the name of the song that you want to play. You have to
make a new folder under your project with name raw and place the music file into it.
Once you have created the Mediaplayer object you can call some methods to start or
stop the music. These methods are listed below.
mediaPlayer.start();
mediaPlayer.pause();
On call to start() method, the music will start playing from the beginning. If this method
is called again after the pause() method, the music would start playing from where it is
left and not from the beginning.
In order to start music from the beginning, you have to call reset() method. Its syntax is
given below.
mediaPlayer.reset();
1
isPlaying()
This method just returns true/false indicating the song is playing or not
2
seekTo(position)
This method takes an integer, and move song to that particular position millisecond
3
getCurrentPosition()
4
getDuration()
5
reset()
6
release()
7
setVolume(float leftVolume, float rightVolume)
8
setDataSource(FileDescriptor fd)
9
selectTrack(int index)
This method takes an integer, and select the track from the list on that particular index
10
getTrackInfo()