0% found this document useful (0 votes)
16 views

Unit - 5

Uploaded by

mayankahir81
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Unit - 5

Uploaded by

mayankahir81
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 43

Diploma- C.E.

Introduction to Unit no:-5

Android Mobile Computing


[09CE1501]

Prof. Rushi Raval


 API is the acronym for Application Programming
Interface.
 which is a software intermediary that allows two
applications to talk to each other.
 Each time you use an app like Facebook, send an
APIs instant message, or check the weather on your
phone, you’re using an API.
 Your phone’s data is never fully exposed to the
server, and likewise the server is never fully exposed
to your phone
Android
Architecture
 Linux kernel
 This provides a level of abstraction between the
device hardware and it contains all the essential
hardware drivers like camera, keypad, display etc.
 The kernel handles all the things that Linux is really
good at such as networking and a vast array of device
Android drivers, which take the pain out of interfacing to
peripheral hardware.
Architecture  Libraries
 On top of Linux kernel there is a set of libraries
including open-source Web browser engine WebKit,
well known library libc, SQLite database.
 It is a useful repository for storage and sharing of
application data, libraries to play and record audio
and video.
 Android Libraries
 This category encompasses those Java-based libraries
that are specific to Android development.
 Examples of libraries in this category include the
application framework libraries:
1. android.app − Provides access to the application
model and is the cornerstone of all Android
Android applications.
Architecture 2. android.content − Facilitates content access,
publishing and messaging between applications
and application components.
3. android.database − Used to access data
published by content providers and includes SQLite
database management classes.
4. android.opengl − A Java interface to the OpenGL
ES 3D graphics rendering API.
 Android Runtime
 This section provides a key component called Dalvik
Virtual Machine which is a kind of Java Virtual
Machine specially designed and optimized for
Android.
Android  The Dalvik VM makes use of Linux core features like
Architecture memory management and multi-threading, which is
intrinsic in the Java language.
 The Dalvik VM enables every Android application to
run in its own process, with its own instance of the
Dalvik virtual machine.
 Application Framework
 The Application Framework layer provides many higher-
level services to applications in the form of Java classes.
 The Android framework includes the following key
services −
1. Activity Manager − Controls all aspects of the
application lifecycle and activity stack.
Android 2. Content Providers − Allows applications to publish
Architecture and share data with other applications.
3. Resource Manager − Provides access to non-code
embedded resources such as strings, color settings and
user interface layouts.
4. Notifications Manager − Allows applications to
display alerts and notifications to the user.
5. View System − An extensible set of views used to
create application user interfaces.
 Applications
 You will find all the Android application at the top
layer.
Android  You will write your application to be installed on this
Architecture layer only.
 Examples of such applications are Contacts Books,
Browser, Games etc.
 Application components are the essential building
blocks of an Android application.
Application  These components are loosely coupled by the
Component application manifest file AndroidManifest.xml that
describes each component of the application and how
s they interact.
 There are following four main components that can be
used within an Android application:
Application 1. Activities
Component 2. Services
s 3. Broadcast Receivers
4. Content Providers
 Activities
 An activity represents a single screen with a user
interface.

Application  in-short Activity performs actions on the screen.


 For example, an email application might have one
Component activity that shows a list of new emails, another
s activity to compose an email.
 Example:
 public class MainActivity extends Activity {
}
 Services
 A service is a component that runs in the background
to perform long-running operations.
 For example, a service might play music in the
Application background while the user is in a different application.

Component  it might fetch data over the network without blocking


user interaction with an activity.
s  Example:
 public class MyService extends Service {
}
 Broadcast Receivers
 Broadcast Receivers simply respond to broadcast
messages from other applications.
 For example, applications can also initiate broadcasts
Application to let other applications know that some data has
been downloaded to the device and is available for
Component them to use.

s  Example:
 public class MyReceiver extends BroadcastReceiver
{
 public void onReceive(context,intent){}
}
 Content Providers
 A content provider component supplies data from one
application to others on request.
 Such requests are handled by the methods of the
ContentResolver class.
Application  The data may be stored in the file system, the
Component database or somewhere else entirely.
s  Example:
 public class MyContentProvider extends
ContentProvider {
 public void onCreate(){}
}
 There are additional components which will be used in
the construction of above mentioned entities, their
logic, and wiring between them. They are:
 1. Fragments-Represents a portion of user interface
in an Activity.
Additional  2. Views-UI elements that are drawn on-screen
including buttons, lists forms etc.
Componen  3. Layouts-View hierarchies that control screen
ts format and appearance of the views.
 4. Intents-Messages wiring components together
 5. Resources-External elements, such as strings,
constants and drawable pictures.
 6. Manifest-Configuration file for the application.
 AndroidManifest.xml 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:
1. It is responsible to protect the application to
Android access any protected parts by providing the
Manifest permissions.
2. It also declares the android api that the
File application is going to use.
3. It lists the instrumentation classes. The
instrumentation classes provides profiling and
other information.
 This is the required xml file for all the android
application and located inside the root directory
 The elements used in the above xml file are described
below:
 <manifest>
 manifest is the root element of the
Elements AndroidManifest.xml file. It has package attribute
of the that describes the package name of the activity class.
 <application>
Android  application is the sub element of the manifest. It
Manifest.x includes the namespace declaration.
ml file  This element contains several sub elements that
declares the application component such as activity
etc.
 The commonly used attributes are of this element are
icon, label, theme etc.
 <activity>
 activity is the subelement of application and
Elements represents an activity that must be defined in the
of the AndroidManifest.xml file.
 It has many attributes such as label, name, theme,
Android launchMode etc.
Manifest.x  <intent-filter>

ml file  intent-filter is the sub-element of activity that


describes the type of intent to which activity, service
or broadcast receiver can respond to
Elements  <action>
of the  It adds an action for the intent-filter. The intent-filter
Android must have at least one action element.
 <category>
Manifest.x  It adds a category name to an intent-filter.
ml file
 Android is a free open-source operating system.
 The Android source tree is located in a Git repository
Android hosted by Google.
 The Git repository includes metadata for the Android
Source source, including changes to the source and when the
changes were made.
 The Android Open Source Project (AOSP) is an
initiative created to guide development of the Android
mobile platform.
 The Android platform consists of the operating system
(OS), middleware and integral mobile applications.
Android  The AOSP (Android Open Source Project) is free to
Open download, free to alter, free to build into a product
that can power just about anything.
Source
Project
(AOSP)
 Windows:
 To install Android Studio on Windows, proceed as
follows:
1. If you downloaded an .EXE file (recommended),
Installation double-click to launch it.

of Android 2. Follow the setup wizard in Android Studio and


install any SDK packages that it recommends.
3. As new tools and other APIs become available,
Android Studio tells you with a pop-up, or you can
check for updates by clicking Help > Check for
Update.
 MAC:
 To install Android Studio on your Mac, proceed as
follows:
1. Launch the Android Studio DMG file.

Installation 2. Drag and drop Android Studio into the Applications


folder, then launch Android Studio.
of Android 3. Select whether you want to import previous
Android Studio settings, then click OK.
4. The Android Studio Setup Wizard guides you
through the rest of the setup, which includes
downloading Android SDK components that are
required for development.
 Linux
 To install Android Studio on Linux, proceed as follows:
1. Unpack .ZIP file you downloaded to an appropriate
location for your applications, such as within
/user/local/.

Installation 2. To launch Android Studio, open a terminal, navigate


to the android-studio/bin/. directory, and
of Android execute studio.sh
3. Select whether you want to import previous
Android Studio settings or not, then click OK.
4. The Android Studio Setup Wizard guides you
through the rest of the setup, which includes
downloading Android SDK components that are
required for development.
 Android Studio is the official Integrated Development
Environment (IDE) for Android app development.
 Android Studio offers even more features that
enhance your productivity when building Android
apps, such as:
Developme  A flexible Gradle-based build system

nt  A fast and feature-rich emulator.


 A unified environment where you can develop
Environmen for all Android devices.
t  Apply Changes to push code and resource
changes to your running app without restarting
your app.
 Code templates and GitHub integration to help
you build common app features and import
sample code.
 Each project in Android Studio contains one or more
modules with source code files and resource files.
 Types of modules include:
Developme  Android app modules
nt  Library modules
Environmen  Google App Engine modules

t  By default, Android Studio displays your project files


in the Android project view,
 To see the actual file structure of the project, select
Project from the Project dropdown
 each app module contains the following folders:
Developme  manifests: Contains the AndroidManifest.xml file.

nt  java: Contains the Java source code files, including


JUnit test code.
Environmen  res: Contains all non-code resources, such as XML
t layouts, UI strings, and bitmap images.
Developme
nt
Environmen
t- The user
interface
1. The toolbar lets you carry out a wide range of actions,
including running your app and launching Android tools.
2. The navigation bar helps you navigate through your
project and open files for editing. It provides a more
compact view of the structure visible in the Project
Developme window.

nt 3. The editor window is where you create and modify code.


Depending on the current file type, the editor can change.
Environmen For example, when viewing a layout file, the editor
displays the Layout Editor.
t- The user 4. The tool window bar runs around the outside of the IDE
window and contains the buttons that allow you to expand
interface or collapse individual tool windows.
5. The tool windows give you access to specific tasks like
project management, search, version control, and more.
You can expand them and collapse them.
6. The status bar displays the status of your project and the
IDE itself, as well as any warnings or messages.
Tool window Windows and Linux Mac
Project Alt+1 Command+1
Version Control Alt+9 Command+9

Developme Run
Debug
Shift+F10
Shift+F9
Control+R
Control+D
nt Logcat Alt+6 Command+6
Environmen Return to Editor Esc Esc

t- Keyboard Hide All Tool Windows Control+Shift+F12


Command+Shift+F
12
Shortcuts
 Before you start, there are two fundamental concepts
First that you need to understand about Android apps:

Android App 1. how they provide multiple entry points


2. how they adapt to different devices
 Apps provide multiple entry points
 Android apps are built as a combination of
components that can be invoked individually.
 For example, an activity is a type of app component
that provides a user interface (UI).
First  The "main" activity starts when the user taps your
app's icon.
Android App  You can also direct the user to an activity from
elsewhere, such as from a notification or even from a
different app.
 Other components, such as broadcast receivers and
services, allow your app to perform background tasks
without a UI
 Apps adapt to different devices
 Android allows you to provide different resources for
different devices.
 For example, you can create different layouts for
different screen sizes. The system determines which
layout to use based on the screen size of the current
First device.
Android App  If any of your app's features need specific hardware,
such as a camera, you can query at runtime whether
the device has that hardware or not, and then disable
the corresponding features if it doesn't.
 You can specify that your app requires certain
hardware so that Google Play won't allow the app to
be installed on devices without them.
 Create an Android project
 To create your new Android project, follow these
steps:
First 1. Install the latest version of Android Studio
Android App 2. In the Welcome to Android Studio window, click
Start a new Android Studio project.
3. In the Select a Project Template window, select
Empty Activity and click Next.
4. In the Configure your project window, complete
the following:
 Enter "My First App" in the Name field.
 Enter "com.example.myfirstapp" in the Package
name field.
 If you'd like to place the project in a different folder,
First change its Save location.
 Select either Java or Kotlin from the Language
Android App drop-down menu.
 Select the lowest version of Android your app will
support in the Minimum SDK field.
 Leave the other options as they are.
5. Click Finish.
 The ‘Activity’ class is a crucial component of an
Android app
 The way activities are launched and put together is a
fundamental part of the platform's application model.
Working  Unlike programming paradigms in which apps are
with launched with a main() method, the Android system
initiates code in an ‘Activity’ instance.
activities.  The mobile-app experience differs from its desktop
counterpart.
 in that a user's interaction with the app doesn't
always begin in the same place.
 For instance, if you open an email app from your
home screen, you might see a list of emails.
 By contrast, if you are using a social media app that
then launches your email app, you might go directly
to the email app's screen for composing an email.
Working  The ‘Activity’ class is designed to facilitate this
paradigm.
with  When one app invokes another, the calling app
activities. invokes an activity in the other app, rather than the
app as an atomic whole.
 In this way, the activity serves as the entry point for
an app's interaction with the user.
 You implement an activity as a subclass of the
‘Activity’ class.
 An activity provides the window in which the app
draws its UI.
 This window typically fills the screen, but may be
smaller than the screen and float on top of other
windows.
 Generally, one activity implements one screen in an
app.
Working  For instance, one of an app’s activities may
with implement a Preferences screen, while another
activity implements a Select Photo screen.
activities.  Most apps contain multiple screens, which means
they comprise multiple activities.
 Typically, one activity in an app is specified as the
main activity, which is the first screen to appear when
the user launches the app.
 Each activity can then start another activity in order
to perform different actions.
Activity Life
Cycle
 onCreate()
 You must implement this callback, which fires when
the system creates your activity.
 Your implementation should initialize the essential
Activity Life components of your activity
 onStart()
Cycle  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
final preparations for coming to the foreground and
becoming interactive.
 onResume()
 The system invokes this callback just before the
activity starts interacting with the user.
 At this point, the activity is at the top of the activity
stack, and captures all user input.
Activity Life  The onPause() callback always follows onResume().
Cycle  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 Recents button.
 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.
Activity Life  onRestart()
Cycle  The system invokes this callback when an activity in
the Stopped state is about to restart.
 onDestroy()
 The system invokes this callback before an activity is
destroyed.
 This callback is the final one that the activity receives.

You might also like