• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off

Card Range To Study



Play button


Play button




Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

33 Cards in this Set

  • Front
  • Back

Example of UI flexibility

ability to compose/recompose an activity's view at runtime depending on what is required.

e.g., two activities can be next to each other on a tablet, but on a phone it makes more sense for user to swipe from one activity to the second

Can you swap an activity's entire view without destroying it or pass a view from one activity to another at runtime?

No. Activity's are tightly bound to their views. They are not built for this flexibility. Use fragments


controller object that an activity can deputize to perform tasks

UI fragment

fragment that is managing all or part of the UI. Has a view of its own that is inflated from a layout file

If you are using UI fragments, how do you set up the activity's view?

set it up to contain spots where the fragments will be placed.

since the activity is technically staying the same throughout its lifetime, no laws of android are violated

hosting (in terms of activity and UI fragment)

activity is providing a spot in its view hierarchy where the fragment can place its view. fragment views must be within an activity's view in order to appear

How do you manage backwards compatibility for fragments?

support library that takes care of most of it is automatically included in project. To be double certain, modify the base code to extend FragmentActivity instead of Activity

What's a good default superclass to use when creating a new class?


declare a variable to store a unique identifier and then generate a random unique identifier


mID = UUID.randomUUID();

What does UUID stand for?

universal unique identifier

two general things an activity must do in order to host a UI fragment

- define a spot in its layout for the fragment's view

- manage the lifecycle of the fragment instance

two approaches to hosting a UI fragment in an activity

1. Layout fragment

2. Add fragment to code

Pros and cons of adding fragment to activity's layout


inflexible. this hard-wires the fragment to the view, so you can't swap it out during the activity's lifecycle

pros and cons of adding fragment to activity's code

more complex

lets you change the view at runtime

3 basic steps to create a UI fragment

1. compose an interface by defining widgets in a layout file

2. create the class and set its view to the layout you defined

3. wire up the widgets from the layout inflated in the code


unicode transformation format

xml mandates that you reference things using a....


superclass when you're creating a new class for a fragment


this one ensures it will import the right support libraries for backwards compatibility


density independent pixel

How do you create a container to host a layout fragment?

Create a view group within the activity's layout file. You'll create a separate xml file for the fragment, but it will ultimately be placed in this spot

What methods do you need to override in your fragment class?

public void onCreate(Bundle savedInstanceState);

public View onCreate(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState);

Why is Fragment.onCreate(...) public when Activity.onCreate(...) is protected?

Fragment's lifecycle methods must be public so Activity can manage them

What does NOT happen in Fragment.onCreate that is significant?

You don't inflate the view.

Instead, inflate the view in public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)

What do you do in Fragment.onCreateView(...)?

View v = inflater.inflate(R.layout.fragment_crime, parent, false); //false means we won't add the inflated view to the parent. Instead, we're going to do it in the activity's code

//insert code to wire up widgets here!

return v;

What's the difference between getting references for a fragment vs. in an activity?

For a fragment, you do it on onCreateView and must use v.findViewById instead of just findViewById

What does FragmentManager do?

manages fragments and adds their views to the activity's hierarchy

What are the general steps to add a fragment to an activity in code?

1. Get the FragmentManager

2. Give it a fragment to manage

Syntax to get the FragmentManager

FragmentManager fm = getSupportFragmentManager();

Once you have the FragmentManager, how do you give it a fragment to manage?

Fragment fragment = fragMngr.findFragmentById(R.id.fragmentContainer);

if (fragment == null)

fragment = new CrimeFragment();

fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit();

what are fragment transactions used for?

add/remove/detach/replace fragments in the fragment list

FragmentManager.beginTransaction() returns an instance of FragmentTransaction, and then you can take action on the fragments in the list (it tells them apart by the container view)

What methods are called when you add the fragment to the FragmentManager?




Afterward, Activity.onCreated(Bunde) is called, along with Activity.onStart() and Activity.onResume()

Once the fragment's state is caught up to the activity's state, what does the FragmentManager do?

calls corresponding lifecycle methods around the same time the OS receives it. No guarantee of fragment or activity receiving it first

Should you start a program and then add fragments later on?

No, much harder to add fragments later. Plan to have them right away