Professional Documents
Culture Documents
Home
Algorithms +
All Algorithms
Analysis of Algorithms
Searching Algorithms
Sorting Algorithms
Graph Algorithms
Bit Algorithms
Pattern Searching
Geometric Algorithms
Mathematical Algorithms
Randomized Algorithms
Game Theory
Greedy Algorithms
Dynamic Programming
Backtracking
Data Structures +
All Data Structures
Array
LinkedList
Stack
Queue
Binary Tree
Heap
Hashing
Graph
Matrix
Strings
Languages +
C++
Java
Python
SQL
PHP
Javascript
Program Output
Interview +
Company Prep
Top Topics
Interview Experiences
Experienced Interviews
Internship Interviews
Competitive Programming
Design Patterns
Students +
Placement Course
Project
Competitive Programming
Testimonials
Careers
Internship
School Programming
GATE +
GATE CS Corner
GATE Notes
Official Papers
CS Subjects +
Operating Systems
DBMS
Computer Networks
Compiler Design
Web Technology
Digital Electronics
Engg. Mathematics
Theory of Computation
Advanced Topics
What’s Difference?
Quizzes +
C
C++
Java
Python
Data Structures
Algorithms
Operating Systems
DBMS
Compiler Design
Computer Networks
Theory of Computation
Computer Organization
Software Engineering
Engg. Mathematics
Aptitude
GBlog
Puzzles
What’s New?
As it is known that every Android app has at least one activity associated
with it. When the application begins to execute and runs, there are various
state changes that activity goes through. Different events some user-
triggered and some system triggered can cause an activity to do the
transition from one state to another. All the state changes associated with
the activity are part of the activity lifecycle in android. When a certain
event occurs, each activity has to go through different stages of the
Android lifecycle. The state of activity is managed by maintaining the
activity stacks, in which the new activity is on the top of the stack, and the
rest of the activity is below in stack in the order of the time they have been
put in the stack.
There are seven states of an Activity lifecycle, out of these seven states, it is
sure that the activity will be in any of the seven states depending on the
event that occurred.
onCreate()
onStart()
onRestart()
onResume()
onPause()
onStop()
onDestroy()
To have detailed information on how this activity states works and what is
the changes that activity undergoes in each state, refer to the article on
activity lifecycle in android.
Events Leading to Configuration Change/State Change
There are many events that can lead to a configuration change of the
application, which ultimately causes state change of the activities. Let’s
see some events and cases where the activity state changes take place.
Let’s say the user is viewing the app in portrait mode and suddenly the
user changes the orientation of the application to landscape mode. Since
changing the orientation of the application will eventually change the
view, which will lead to a configuration change in the app and the activity
associated with the portrait mode is destroyed and new activity associated
with the landscape mode is created. The running/active activity associated
with the portrait mode will have onPause(), onStop(), and onDestroy()
callbacks triggered. When the user changes the orientation, the new
activity is created and new activity will have onCreate(), onStart(), and
onResume() callbacks triggered.
Below is the sample video in which one can see the changes in states of
activity which it undergoes when the orientation of the app changes. See
the Toast messages to see the activity state changes.
In multi-window mode, although there are two apps that are visible to the
user, there is only the one app with which the user is interacting is in the
foreground and has focus is in the onResume() state and another app that
is in the background and visible to the user is in a Paused state. So it can be
said that the activity with which the user is interacting is the only activity
which is in the resumed state, while all the other activities are started but
not resumed. When the user switches from one app to another app, the
system calls onPause() lifecycle state on the running app, and onResume()
lifecycle state on another app which is previously not in the active state. It
switches between these two methods each time the user toggles between
apps. See the Toast messages to see the activity state changes.
It can be seen that when there are multiple screens running at the same
time, every time when the user resizes one screen relative to another
screen, the original activity gets destroyed and new activity gets created
corresponding to the new screen size
In the above video, the activity covers another activity completely and the
state changes can be observed according to it.
If an activity is in the foreground and is in running state, and the user taps
the Back button, the activity transitions through the onPause(), onStop(),
and onDestroy() callbacks. In addition to being destroyed, the activity has
also removed the stack, which is used for storing the activities in order of
the time put in the stack. It is important to note that, by default, the
onSaveInstanceState() callback is not called in this case as it is assumed
that the user tapped the Back button with no expectation of returning to
the same instance of the activity and so there is no need to save the
instance of the activity. If the user overrides the onBackPressed() method,
it is still highly recommended that the user should invoke
super.onBackPressed() from the overridden method, else if
super.onBackPressed() is not invoked then it may lead to ambiguous
behavior of the application and may lead to bad user experience. See the
Toast messages to see the activity state changes.
COMPANY LEARN
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Video Tutorials
PRACTICE CONTRIBUTE
Company-wise Write an Article
Topic-wise GBlog
Contests Videos
Subjective Questions