0% found this document useful (0 votes)
120 views58 pages

University Institute of Computing: Master of Computer Application Mobile Application Development

Uploaded by

Humanshi Jangra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views58 pages

University Institute of Computing: Master of Computer Application Mobile Application Development

Uploaded by

Humanshi Jangra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 58

UNIVERSITY INSTITUTE OF

COMPUTING
Master of Computer Application
Mobile Application Development.

Prepared By: Manender Dutt

UNIT-1 DISCOVER . LEARN .


EMPOWER
Importance

• Students are able to write and run a Kotlin programs.


• Students are able to work with different control flow
statements.
• Students are able to implement programs based on Object
Oriented Programming.
• Students are able to understand the need of getter and
setters.
• Students are able work with inheritance based programs.
• Students are able to understand the need of collection and
work with different collections. 2
Importance

• Students are able to create and run activities.


• Students are able to work with different activities interaction.
• Students are able to implement programs based on Services in
android.
• Students are able to understand the bunder while using multiple
activities.
• Students are able work with different methods of activity life
cycle.
• Students are able to understand the need of Broadcast receivers
in android development.
3

11/05/22
Topic Objectives
• To write and run a Kotlin programs.
• To work with different control flow statements.
• To implement programs based on Object Oriented
Programming.
• To understand the need of getter and setters.
• To work with inheritance based programs.
• To understand the need of collection and work with
different collections.

4
Topic Objectives

• To understand different android constructs.


• To work with activities and switching between them.
• To implement the life cycle methods of activity.
• To understand the need of Bundles and intents.
• To work with Services.
• To understand the Content Provider and Broadcast Receivers.

11/05/22 5
What is Android ?
• It is an open source.

• Android is a software package and Linux-based Operating


System designed primarily for touch screen mobile devices
such as Smart Phones and Tablet Computers.

• In other words, we can say that it is a mobile operating


system based on Linux kernel.

6
History of Android

• Initially, Andy Rubin founded Android Incorporation in


Palo Alto, California, United States in October, 2003.
• In 17th August 2005, Google acquired Android
Incorporation.
• The key employees of Android Incorporation other than
Andy Rubin are Rich Miner, Chris White and Nick
Sears.

• Developed and Managed by the OHA.

7
Open Handset Alliance

• It’s consortium (Association of two or more


individuals, organizations) of 84 companies.

• It was established on 6th November 2007

• This group of companies are allowed to use source


code of Android and develop applications.

• Reason for Nokia not to develop Android Mobiles is


Nokia is not part of OHA.

8
Features of Android

• It is an Open Source.
• Anyone can customize the Android Platform.
• There are lot of applications that can be chosen by the
customer.
• Application Framework enabling reuse and
replacement of component
• Dalvik Virtual Machine optimized for mobile devices.
• Media support for common audio, video and still image
formats(MPEG4,MP3,AAC,AMR,JPG,PNG,GIF)
• Bluetooth,EDGE,3G,WiFi (hardware dependent)
9
Features of Android

• Camera ,GPS, compass, accelerometer (hardware


dependent)
• It provides many interesting features like weather
details, opening screen, live (RSS) Really Simple
Syndication etc.
• It provides support for messaging services (SMS and
MMS), web browser, storage (SQLite) etc.
• Rich Development Environment including a device
emulator, tools for debugging, memory, performance
profiling and an plugin for the Eclipse IDE.
10
Android Version Images

11
Android Architecture

12
DVM

• Android apps execute on Dalvik


VM, a “clean-room” implementation
of JVM.
-- Dalvik optimized for efficient execution
-- Dalvik: register-based VM, unlike Oracle’s
stack-based JVM
-- Kotlin .class bytecode translated to Dalvik
EXecutable (DEX) bytecode, which Dalvik
interprets

13
Requirements for Android
• Download Android Studio
• From http://developer.android.com/sdk/installing/index.html
• System Requirements for Windows
• Microsoft® Windows® 8/7/Vista (32 or 64-bit)
• 2 GB RAM minimum, 8 GB RAM recommended
• 400 MB hard disk space
• At least 1 GB for Android SDK, emulator system images, and caches
• 1280 x 800 minimum screen resolution
• Kotlin Development Kit (JDK) 7
• Optional for accelerated emulator: Intel® processor with support for Intel®
VT-x, Intel® EM64T (Intel® 64), and Execute Disable (XD) Bit
functionality

14
Installation

Kotlin
•Visit http://www.oracle.com/technetwork/Kotlin/Kotlinse/downloads/index.html
•Install it and Set Path [Select Start menu > Computer > System Properties >
Advanced System Properties. Then open Advanced tab > Environment Variables
and add a new system variable Kotlin_HOME that points to your JDK folder, for
example C:\Program Files\Kotlin\jdk1.7.0_4]

Android Studio
•Visit http://developer.android.com/sdk/index.html and download Download
Android Studio.
•Run executable file of setup.
•Follow the setup wizard to install Android Studio and any necessary SDK tools.

15
Manifest
• Every Android app must include an
AndroidManifest.xml file describing functionality

• The manifest specifies:


– App’s Activities, Services, etc.
– Permissions requested by app
– Minimum API required
– Hardware features required, e.g., camera with
autofocus
– External libraries to which app is linked, e.g., Google
Maps library

16
What is an Activity?
● An Activity is an application component
● Represents one window, one hierarchy of views
● Typically fills the screen, but can be embedded in other Activity or a
appear as floating window
● Kotlin class, typically one Activity in one file

17
What does an Activity do?
● Represents an activity, such as ordering groceries, sending email, or
getting directions
● Handles user interactions, such as button clicks, text entry, or login
verification
● Can start other activities in the same or other apps
● Has a life cycle—is created, started, runs, is paused, resumed, stopped,
and destroyed

18
Examples of activities

19
Apps and activities
● Activities are loosely tied together to make up an app
● First Activity user sees is typically called "main activity"
● Activities can be organized in parent-child relationships in the Android
manifest to aid navigation

20
Layouts and Activities

● An Activity typically has a UI layout


● Layout is usually defined in one or more XML files
● Activity "inflates" layout as part of being created

21
Activity lifecycle

22
Activity Life Cycle

Method Description
onCreate called when activity is first created.
called when activity is becoming
onStart
visible to the user.
called when activity will start
onResume
interacting with the user.
onPause called when activity is not visible to
called when activity is no longer
onStop
visible to the user.
called after your activity is stopped,
onRestart
prior to start.
onDestroy called before the activity is destroyed.

23
What is the Activity Lifecycle?

●The set of states an Activity can be in during its lifetime,


from when it is created until it is destroyed

More formally:
●A directed graph of all the states an Activity can be in, and
the callbacks associated with transitioning from each state
to the next one

24
What is the Activity Lifecycle?

25
Activity states and app visibility
● Created (not visible yet)
● Started (visible)
● Resume (visible)
● Paused(partially invisible)
● Stopped (hidden)
● Destroyed (gone from memory)

State changes are triggered by user action, configuration


changes such as device rotation, or system action
26
Activity lifecycle
callbacks

27
Callbacks and when they are called
onCreate(Bundle savedInstanceState)—static initialization
onStart()—when Activity (screen) is becoming visible
onRestart()—called if Activity was stopped (calls onStart())
onResume()—start to interact with user
onPause()—about to resume PREVIOUS Activity
onStop()—no longer visible, but still exists and all state info preserved
onDestroy()—final call before Android system destroys Activity

28
Activity states and callbacks graph

29
Implementing and overriding callbacks

● Only onCreate() is required


● Override the other callbacks to change default behavior

30
onCreate() –> Created

● Called when the Activity is first created, for example when user taps
launcher icon
● Does all static setup: create views, bind data to lists, ...
● Only called once during an activity's lifetime
● Takes a Bundle with Activity's previously frozen state, if there was one
● Created state is always followed by onStart()

31
onCreate(Bundle savedInstanceState)

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The activity is being created.
}

32
onStart() –> Started

●Called when the Activity is becoming visible to user


●Can be called more than once during lifecycle
●Followed by onResume() if the activity comes to the
foreground, or onStop() if it becomes hidden

33
onStart()

@Override
protected void onStart() {
super.onStart();
// The activity is about to become visible.
}

34
onRestart() –> Started

●Called after Activity has been stopped, immediately before it


is started again
●Transient state
●Always followed by onStart()

35
onRestart()

@Override
protected void onRestart() {
super.onRestart();
// The activity is between stopped and started.
}

36
onResume() –> Resumed/Running

●Called when Activity will start interacting with user


●Activity has moved to top of the Activity stack
●Starts accepting user input
●Running state
●Always followed by onPause()

37
onResume()

@Override
protected void onResume() {
super.onResume();
// The activity has become visible
// it is now "resumed"
}

38
onPause() –> Paused
● Called when system is about to resume a previous Activity
● The Activity is partly visible but user is leaving the Activity
● Typically used to commit unsaved changes to persistent data, stop
animations and anything that consumes resources
● Implementations must be fast because the next Activity is not
resumed until this method returns
● Followed by either onResume() if the Activity returns back to the
front, or onStop() if it becomes invisible to the user

39
onPause()

@Override
protected void onPause() {
super.onPause();
// Another activity is taking focus
// this activity is about to be "paused"
}

40
onStop() –> Stopped
● Called when the Activity is no longer visible to the user
● New Activity is being started, an existing one is brought in
front of this one, or this one is being destroyed
● Operations that were too heavy-weight for onPause()
● Followed by either onRestart() if Activity is coming back
to interact with user, or onDestroy() if Activity is going
away

41
onStop()

@Override
protected void onStop() {
super.onStop();
// The activity is no longer visible
// it is now "stopped"
}

42
onDestroy() –> Destroyed
● Final call before Activity is destroyed
● User navigates back to previous Activity, or configuration
changes
● Activity is finishing or system is destroying it to save space
● Call isFinishing() method to check
● System may destroy Activity without calling this, so use
onPause() or onStop() to save data or state

43
onDestroy()

@Override
protected void onDestroy() {
super.onDestroy();
// The activity is about to be destroyed.
}

44
Activity instance
state

45
When does config change?

Configuration changes invalidate the current layout or other resources in your


activity when the user:
●Rotates the device
●Chooses different system language, so locale changes
●Enters multi-window mode (from Android 7)

46
What happens on config change?

On configuration change, Android:


1. Shuts down Activity
by calling:
2. Starts Activity over again
by calling:
● onPause() ● onCreate()
● onStop() ● onStart()
● onDestroy() ● onResume()

47
Activity instance state
● State information is created while the Activity is running,
such as a counter, user text, animation progression

● State is lost when device is rotated, language changes,


back-button is pressed, or the system clears memory

48
Saving and
restoring
Activity state

49
What the system saves
●System saves only:
○ State of views with unique ID (android:id) such as
text entered into EditText
○ Intent that started activity and data in its extras

●You are responsible for saving other activity and user


progress data

50
Saving instance state

Implement onSaveInstanceState() in your Activity

●Called by Android runtime when there is a possibility the


Activity may be destroyed
●Saves data only for this instance of the Activity during
current session

51
onSaveInstanceState(Bundle outState)
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Add information for saving HelloToast counter
// to the to the outState bundle
outState.putString("count",
String.valueOf(mShowCount.getText()));
}

52
Restoring instance state

Two ways to retrieve the saved Bundle


●in onCreate(Bundle mySavedState)
Preferred, to ensure that your user interface, including any saved state, is
back up and running as quickly as possible
●Implement callback (called after onStart())
onRestoreInstanceState(Bundle mySavedState)

53
Restoring in onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mShowCount = findViewById(R.id.show_count);

if (savedInstanceState != null) {
String count = savedInstanceState.getString("count");
if (mShowCount != null)
mShowCount.setText(count);
}
}

54
onRestoreInstanceState(Bundle state)

@Override
public void onRestoreInstanceState (Bundle mySavedState) {
super.onRestoreInstanceState(mySavedState);

if (mySavedState != null) {
String count = mySavedState.getString("count");
if (count != null)
mShowCount.setText(count);
}
}

55
Instance state and app restart

When you stop and restart a new app session, the Activity instance
states are lost and your activities will revert to their default
appearance

If you need to save user data between app sessions, use shared
preferences or a database.

56
BIBLIOGRAPHY

Text Books-
•Android Programming for Beginners by John Horton
•Reto Meier, “Profesional Android 4 Aplication Development” ,
John Wiley& Sons, Inc, 2012.

Reference Material-
•Zigurd Mednieks, Laird Dornin, Blake Meike G, and Masumi
Nakamura, “Programming Android”, O’Reily boks

11/05/22 57
Thank You

11/05/22 58

You might also like