03 Activities and Intents Flashcards

1
Q

Activity

A
● A single screen with a user interface 
● Has a unique purpose 
● Strung together to accomplish some task
     ● Can be from other applications 
● Extended from the Activity class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Manifest

A

● AndroidManifest.xml – each app has one ● Ties everything together
● Tells the system what components you have
● Activities, Services, ContentProviders, and BroadcastReceivers
● Registers Intents that you want to handle from other apps
● What permissions and device hardware you require
● Minimum and target platform API

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explicit Intents

A

● Directly tell a specific Activity or Service to do something
● The email app’s Inbox Activity tells the
MessageViewerActivity to display an email when the user clicks on a message

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Implicit Intents

Real world example

A

(Implied)
Call on an unknown component to do something
View a photo, Send a message to someone
Ask the Android Framework: Is there an app on this device that can handle this task?
User often gets to pick what app to use, if more than one app can handle the request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Implicit Intents

A

● Lets anonymous application components service action requests
● Thus you can ask the system to start an Activity to
perform an action without knowing which application or activity will be started
● Cool, but be careful
● You don’t always know if your user has something on their phone to handle the intent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Statefulness

A

Mobile apps run on limited devices
● Memory
● CPU
● Network conditions
Mobile apps must play nicely with other apps
● Incoming calls.
● User switches to other app
● Another app might need the camera
● Low memory conditions
As devices get more advanced, this problem becomes less of a problem to “end programmers”
● But this will still be a few years away
● Will be handled by the framework more seamlessly
Will never stop being important to user experience
● Never lose your user’s data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Activity Lifecycle (Why?)

A

Your app should always be able to quickly go away, and then quickly come back
● But make it look like nothing happened

Why?
● Statefulness: Limited resources on mobile. Other apps want to run, too
● Screen changes. Automatically switch resources from landscape to portrait

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

An activity has essentially four states:

A
  • If an activity is in the foreground of the screen (at the top of the stack), it is active or running.
  • If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (maintains state and member), but can be killed by the system in extreme low memory situations.
  • If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user.
  • If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Activity lifecycle steps

A
● onCreate 
● onStart / onRestart 
● onResume 
● onPause 
● onSaveInstanceState 
● onStop 
● onDestroy

Can skip back to state if not being destroyed completely

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

a. OnCreate

A
Do most of the initialization
Set the layout for the activity
Find UI Views and hook up listeners
Restore previous saved instance values
Read Intents

As quickly as possible (under 2 seconds)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

b. onSaveInstanceState

A

Save the state of the user
interface
The framework will do much
of this for you

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

c. onCreate

A

Restore your saved UI state
with savedInstanceState
bundle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

d. onPause

A

Stop animations
Stop long-running operations
Save your user data to storage
Release sensors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

e. onResume

A

Start or restart your animations
Resume long-running operations
Re-acquire sensors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Activity and Fragment Lifecycles

A

That is a simplified version But it pretty much covers over 95% of use cases

  1. onCreate/onCreateView – Create stuff. Read Intents. Restore UI
  2. onResume – Resume stuff you’ve paused 3. onPause – Pause stuff. Save Data.
  3. onSaveInstanceState… – Save UI stuff.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Saving State

A

Must save
Anything stored in a member variable

Saved by framework
Anything stored inside a View

17
Q

Saving State / Intent Arguments

A
Can only write:
● Primitive types
● Arrays
● Strings
● Serializable classes
     o "Flattening" complex classes 
● Parcelable classes
     o Android specific alternative to    
Serializable 
● Other Bundles
18
Q

Lifetime of framework

A

The “lifetime” of the Android framework object for each Activity is different from the “lifetime” of the Java object for an Activity