Android Life Cycle
Android Life Cycle
YEAR 2024
Activity Lifecycle
After completing this chapter, you should be able to:
• onCreate() is not required for apps. But the reason it is used in app
is because that method is the best place to put initialization code.
List of Activity Lifecycle Methods or
States: Activity Created: onCreate():
• The initialization code can be placed in onStart() or
onResume() and when the app load first, it will work the same
as in onCreate().
List of Activity Lifecycle Methods or
States: Activity Started: onStart():
• onStart() method is called just after it’s creation. In other case
Activity can also be started by calling restart method i.e after
activity stop.
• Activity also gets paused before stop called in case user press
the back navigation button. The activity will go in paused state
for these reasons also if a notification or some other dialog is
overlaying any part (top or bottom) of the activity (screen).
List of Activity Lifecycle Methods or
States: Activity Started: onPause():
• Similarly, if the other screen or dialog is transparent then user
can see the screen but cannot interact with it. For example, if
a call or notification comes in, the user will get the
opportunity to take the call or ignore it.
• After the Activity is destroyed if user again click the app icon,
in this case activity will be recreated and follow the same
lifecycle again.
Fragment Lifecycle
• In Android, Fragment is a part of an activity which enable
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 pane UI
and reuse a Fragment in multiple Activities. A fragment must
always be embedded in an activity and the fragment’s life-
cycle is directly affected by the host activity’s life-cycle.
List of Activity Lifecycle Methods or
States: Activity Started: onStart():
• When activity launch, first onCreate() method call then
onStart() and then onResume().
• Further two more View (i.e. 2 EditText ) are nested inside Relative Layout ViewGroup. It
is important to note that one layout can be nested in another layout.
XML in Android: Basics of User Interface
The below code snippet will explain the above image in better way. Paste it in
activity_main.xml:
<Button
android:id="@+id/buton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
XML in Android: Basics of User Interface
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sample Text"
android:layout_marginTop="15dp"
android:textSize="30dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
XML in Android: Basics of User Interface
<EditText
android:id="@+id/editTextName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="First Name"
/>
<EditText
android:id="@+id/editTextLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Last Name"/>
</RelativeLayout>
</LinearLayout>
Application Signing for Trust Relationships
• Every Android application screen has some components like button, Text
or images.
• These are contained inside the ViewGroup. Layouts are the best examples
for ViewGroups.
• The different types of layout in android are Linear Layout, Relative Layout,
Absolute Layout, Table Layout and Frame Layout.
•
Android TextView
• In Android, TextView displays text to the user and optionally allows them
to edit it programmatically. TextView is a complete text editor, however
basic class is configured to not allow editing but we can edit it.
• View is the parent class of TextView. Being a subclass of view the text
view component can be used in your app’s GUI inside a ViewGroup, or
as the content view of an activity.
Attributes of TextView: The attributes that helps us to configure a TextView in your xml file.
id: id is an attribute used to uniquely identify a text view. An example is given in the above code
findViewById(R.id.textView);
text: setting the text in a textview programmatically means in java class.
In Java class:
simpleCheckBox.setTextColor(Color.RED);
Android CheckBox
• textSize: textSize attribute is used to set the size of text of a check box.
simpleCheckBox.setTextSize(20);
Android CheckBox
• background: background attribute is used to set the background of a
check box.
• Meanwhile, Nokia released one of the first slider phones, the 8110, fondly
referred to as “The Matrix Phone” because the phone was heavily used in
films
• The 8110 could display four lines of text with 13 characters per line. See
figure 1.3 in page 15.
History of Mobile Software Development
continued…
Wireless Application Protocol (WAP)
• With their postage stamp size low resolution screens and limited storage
and processing power, these phones could not handle the data-intensive
operations required by traditional Web browsers
• The bandwidth requirements for data transmission were also costly to the
user
• The Wireless Application Protocol (WAP) standard merged to address
these concerns. Simply put, WAP was a stripped down version of
Hypertext Transfer Protocol (HTTP), which is the backbone protocol of the
WWW
History of Mobile Software Development
continued…
• Unlike traditional Web browsers, WAP browsers were designed to run
within the memory and bandwidth constraints of the phone
• Third-party WAP sites served up pages written in a markup language
called Wireless Markup Language (WML).
• These pages were then displayed on the phone’s WAP browser. Users
navigated as they would on the Web, but the pages were much simpler
in design
• The WAP solution was great for handset manufacturers. The pressure was
off, they could write one WAP browser to ship with the handset and rely
on developers to come up with the content users wanted.
History of Mobile Software Development
continued…
• The WAP solution was great for mobile operators. They could provide a
custom WAP portal, directing their subscribers to the content they wanted
to provide and collect in the data charges associated with browsing which
were often high
• For the first time, developers had a chance to develop content for phone
users, and some did so with limited success.
• Few gained any traction in the customer market because the content was
limited value and the end user experience left much to be desired
History of Mobile Software Development
continued…
• Most of the early WAP sites were extensions of popular branded websites
such as CNN.com and ESPN.com which were looking for new ways to extend
their readership
• Suddenly, phone users could access the news, stock market quotes and sports
scores on their phones
• Commercialising WAP applications was difficult and there was no built-in
billing mechanism
• Some of the most popular commercial WAP applications that emerged during
this time were simple wallpaper and ringtone catalogues that enabled users to
personalise their phones for the first time
History of Mobile Software Development
continued…
• For example, a user browsed a WAP site and requested a specific item. He
filled out a simple order form with his phone number and his handset
model. It was up to the content provider to deliver an image or audio file
compatible with the given phone
• Payment and verification were handled through various premium priced
delivery mechanisms such as Short Message Services (SMS), Enhanced
Messaging Service (EMS), Multimedia Messaging Service (MMS) and
WAP Push.
• WAP browsers in the early days were slow and frustrating. Typing long
URLs with the numeric keypad was time-consuming
History of Mobile Software Development
continued…
• WAP pages were often difficult to navigate, most sites were written one
time for all phones and did not account for individual phone
specifications.
• It did not matter if the end user’s phone had a big screen or a postage
stamp-size monochrome screen; the developer could not tailor the user’s
experience
• The result was a mediocre and not very compelling experience for
everyone involved.
• Content providers often did not bother with a WAP site and instead just
advertised SMS short codes on TV and in magazines.
History of Mobile Software Development
continued…
• In this case, the user sent a premium SMS message with a request for a
specific wallpaper or ringtone. And the content provider sent it back.
• Mobile operators generally liked these delivery mechanisms because they
received a large portion of each messaging fee.
• WAP fell short of commercial expectations. In some markets such as Japan, it
flourished whereas in others like Unites States, it failed to take off.
• Handset screens were too small for surfing; reading a sentence fragment at a
time, and then waiting seconds for the next fragment to download, ruined the
user experience, especially because every second of downloading was often
charged to the user.
History of Mobile Software Development
continued…
• As a result, critics began to call WAP “Wait to Pay”.
• Finally, the mobile operators who provided the WAP portal (the default
home page loaded when you started your WAP browser) often restricted
which WAP sites were accessible.
• The portal enabled the operator to restrict the number of sites users could
browse and to funnel subscribers to the operator’s preferred content
providers and exclude competing sites.
• This kind of walled garden approach further discouraged third-party
developers, who already faced difficulties in monetarising applications,
from writing applications
History of Mobile Software Development
continued…
Proprietary Mobile Platforms
• Writing robust applications with WAP, such as graphics-intensive video
games, was nearly impossible. The 18-to-25 year old sweet-spot
demographic, the kid with the disposable income most likely to
personalise their phones with wallpaper and ringtones; looked at their
portable gaming systems and asked for a device that was both a phone
and a gaming device or a phone and a music player.
• They argued that is devices such as Ninten-do’s Game Boy could provide
hours of entertainment with only five buttons, why not just add phone
capabilities?
History of Mobile Software Development
continued…
Proprietary Mobile Platforms
• Others looked at their digital cameras, Palms, BlackBerries, iPods, even their
laptops and asked the same question; the market seem to be teetering on the
edge of device convergence.
• Memory was getting cheaper, batteries were getting better, and PDAs and
other embedded devices were beginning to run compact versions of common
operating systems such as Linux and Windows.
• The traditional desktop application developer was suddenly a player in the
embedded device market, especially with smartphone technologies such as
Windows Mobile, which they found familiar.
History of Mobile Software Development
continued…
Proprietary Mobile Platforms
• Handset manufacturers realised that if they wanted to continue to sell
traditional handset, they needed to change their protectionist policies
pertaining to handset design and expose their internal frameworks to some
extent.
• A variety of proprietary platforms emerged for traditional handsets. Some
smartphone devices ran Palm OS (later known as WebOS) and IRM BlackBerry
OS.
• Sun Microsystems took its popular Java platform and J2ME emerged (now
known as Java Micro Edition [Java MEJ]
History of Mobile Software Development
continued…
Proprietary Mobile Platforms
• Chipset maker Qualcomm developed and licensed its Binary Runtime Environment for
Wireless (BREW)
• Other platforms, such as Symbian OS, were developed by handset manufacturers such
as Sony Ericsson, Motorola, and Samsung. The Apple iPhone OS (OS X iPhone) joined
the ranks in 2008.
• Many of these platforms operate associated developer programs. These programs keep
developer communities small, vetted, and under contractual agreements on what they
can and cannot do. These programs are often required, and developers even pay to
participate.
• Each platform has benefits and drawbacks and developers love to debate about which
platform is “the best.”
History of Mobile Software Development
continued…
Proprietary Mobile Platforms
• The truth is that no one platform has emerged victorious. Some platforms are best suited for
commercialising games and making millions if your company has brand backing.
• Other platforms are more open and suitable for the hobbyist or vertical market applications
• No mobile platform is best suited for all possible applications. As a result, the mobile phone
market has become increasingly fragmented, with all platforms parts of the pie.
• For manufacturers and mobile operators, handset product lines quickly became complicated.
Platform market penetration varies greatly by region and user demographic.
• Instead of choosing just one platform, manufacturers and operators have been forced to sell
phones for all different platforms to compete in the market.
• For example, BlackBerry 10 phones provide a runtime support Android applications
History of Mobile Software Development
continued…
Proprietary Mobile Platforms
• The mobile developer community has become as fragmented as the market. It
is nearly impossible to keep track of all the changes. Developer specialty
niches have formed. The platform development requirements vary greatly.
• When this approach did not yield the intended results, Google decided on
a different approach, to revamp the entire system upon which application
development was based, hoping to provide a more open environment for
users and developers: the Internet Model
• Google is not the only organisation that is involved in this initiative but it is the
driving force behind the platform.
History of Mobile Software Development
continued…
The Open Handset Alliance
Manufacturers: Designing Android Devices
• More than half the members of the OHA are device manufacturers, such as
Samsung, Motorola, Dell, Sony Ericsson, HTC and LG and semiconductor
companies such as Intel, Texas Instruments, ARM, NVIDIA, and Qualcomm
• The first shipping Android handset, the T-Mobile G1, was developed by handset
manufacturer HTC with service provided by T-Mobile and released in 2008.
• Many other Android handsets were scheduled for 2009 and early 2010. the
platform gained momentum relatively quickly.
History of Mobile Software Development
continued…
The Open Handset Alliance
Manufacturers: Designing Android Devices
• By the fourth quarter of 2010, Android had come to dominate the smartphone
market, gaining ground steadily against competitive platforms such as Research in
Motion (RIM) BlackBerry, Apple iOS, and Windows Mobile.
• As of May 2013, Android devices were being shipped to more than 130 countries,
more than 1,5 million new Android devices were being activated every day, and
about 9000 million devices have been activated in total
History of Mobile Software Development
continued…
The Open Handset Alliance
Manufacturers: Designing Android Devices
• The advantages of widespread manufacturer and carrier support appear to be
really paying off at this point.
• Many developers use these devices for building and testing their applications
because they are the only devices in the world that receive the latest Android
operating system upgrades as they are released.
• If you too, would like your applications to work on the latest Android operating
system version, you should consider investing in one or more of these devices.
History of Mobile Software Development
continued…
The Open Handset Alliance
Apps Drive Device Sales: Developing Android Applications
• When users acquire Android devices, they need those killer apps, right?
• Initially, Goggle led the pack in developing Android applications, many of which, such as
the email client and Web browser, are core features of the platform.
• They also developed the first successful distribution platform for third-party Android
applications: the Android Market, now known as the Google Play store.
• The Google play store remains the primary method by which users download apps, but
it is no longer the only distribution mechanism for Android apps.
• Since July 2013, there have been more than 50 billion application installations from the
Google Play store.
History of Mobile Software Development
continued…
The Open Handset Alliance
Apps Drive Device Sales: Developing Android Applications
• This takes into account only application installations from one marketplace, not
the many other applications sold individually or on other markets.
• These numbers also do not take into account all the Web applications that target
mobile devices running the Android platform.
• This opens up even more application choices for Android users and more
opportunities for Android developers
• The Google Play store has recently received a significant redesign, and there has
been a growing effort to increase the exposure and sales of game applications.
History of Mobile Software Development
continued…
The Open Handset Alliance
Apps Drive Device Sales: Developing Android Applications
• One way Google plans to increase the distribution of games is by providing the new
Google Play Game Services SDK.
• This SDK will allow developers to add real time social features to games and application
programming interfaces (APIs) for implementing leaderboards and achievements to
help drive new users to applications, while continuing to engage existing users.
• Another reason for the Google Play redesign is to help drive sales of content. Users are
always looking for new music, movies, TV shows, books, magazines, and more, and
Google Play’s focus on content has placed it in a position to keep up with user
demand for such services.
History of Mobile Software Development
continued…
The Open Handset Alliance
Taking Advantage of all Android has to Offer
• Android’s open platform has been embraced by much of the mobile development
community extending far beyond the members of the OHA.
• As Android devices and applications have become more readily available, many
other mobile operators and device manufacturers have jumped at the chance to
sell Android devices to their subscribers, especially given the cost benefits
compared to proprietary platforms.
• The open standard of the Android platform has resulted in reduced operator costs
in licensing and loyalties, and we are now seeing a migration to more open devices
History of Mobile Software Development
continued…
The Open Handset Alliance
Taking Advantage of all Android has to Offer
• The market has cracked wide open; new types of users are able to consider
smartphones for the first time. Android is well suited to fill this demand.
History of Mobile Software Development
continued…
The Android Marketplace: Where we are now
The Android market place continues to grow at an aggressive rate on all fronts
(devices, developers and users). Lately, the focus has been on several topics:
• Competitive hardware and software feature upgrades: the Android SDK
developers have focused on providing APIs for features that are not available on
competing platforms to move Android ahead in the market. For example, recent
releases of the Android SDK have featured significant improvements such as
Google Now contextual services
• Expansion beyond smartphones: tablet usage is on the rise with Android users.
There are many new tablets on the market with Android Jelly Bean that come in
many different sizes and form factors
History of Mobile Software Development
continued…
The Android Marketplace: Where we are now
• Some hardware manufacturers are even using Android for gaming consoles. Some
hardware manufacturers are even using Android for gaming consoles, smart
watches, and TVs, in addition to many other types of devices that require an
operating system
• Improved user-facing features: the Android development team has shifted its
focus from feature implementation to providing user-facing upgrades and
“chrome.” They have invested heavily in creating a smoother, faster, more
responsive user interface, in addition to upgrading their design documentation
with excellent trainings with best practices for developers to follow.
History of Mobile Software Development
continued…
The Android Marketplace: Where we are now
• Improved user-facing features: those principles are centered around three goals
and focused on the user experience: “Enchant me,” “Simplify my life,” and “Make
me amazing. ” Following these principles should help any application increase
usability.
History of Mobile Software Development
continued…
Android Platform Differences
The Android platform itself is hailed as “the first complete, open, and free mobile
platform”:
• Complete: the designers took a comprehensive approach when they developed
the Android platform. They began with a secure operating system and built a
robust software framework on top that allows for rich application development
opportunities.
• Open: the Android platform is provided through open-source licensing. Developers
have unprecedented access to the device features when developing applications.
• Free: Android applications are free to develop. There are no licensing fees for
developing on the platform. No required membership fees and testing fees.
History of Mobile Software Development
continued…
Android Platform Differences
• Free: No required signing or certification fees. Android applications can be
distributed and commercialised in a variety of ways. There are no costs for
distributing your applications on your own, but to do so in Google Play store
requires registration and paying a small, one time $25 fee.
• The term free implies there might actually be costs for development, but they are
not mandated by the platform. Costs for designing, developing, testing, marketing,
and maintaining are not included. If you provide all of these, you may not be laying
out cash, but there is a cost associated with them. The $25 developer registration
fee is designed to encourage developers to create quality applications.