COP4656 Midterm/Quiz Review

Ace your homework & exams now with Quizwiz!

For a LinearLayout, what is orientation, what are the possible values, how do they effect the Views added to them?

For a LinearLayout, the orientation is what determines whether the Views inside of the Layout will be stacked from up to down inside the Layout, or left to right. The 2 possible values are vertical, for top to bottom, and horizontal for left to right. This affects the views by forcing them to be stacked in a linear fashion (either vertically or horizontally) inside the Layout.

Write all the android:inputType attributes that occur in the list below.

Number, decimal (numberDecimal), signed (numberSigned), date, time, datetime, text, email (TextEmailAddress), and phone.

Which function, from the list below, do you call when you want to kill your Activity? This call is made from inside the Activity.finalize()onDestroy()finish()onStop()onKill()

finish()

What can you use to run your Android apps if you don't have a device?

An Android Emulator, which is given as an SDK in Android Studio.

Android 7.0, named Nougat, was released several years ago. What is the latest non-preview version of Android, what is its name, and what is the newest API?

Android 10

Name five SDK tools at your disposal when programming in Android Studio.

Android Emulator, Google Play Services, Google Web Driver, NDK (Side by side), and GPU debugging tools.

What is the name of the IDE we are using?

Android Studio.

A(n) ___ ___ is an interface in the View class that contains a single call back method.

Event Listener.

What happens if two or more intents are resolved to the same intent filter? What does the system or user do?

If multiple Intents match the same action in the same IntentFilter, the user is presented with the option to use of them over the other.

Assume the scenario listed below. Write which life cycle states (i.e. on-Functions) occur throughout the scenario, in order, and explain when they occur (i.e. are called). Scenario: You just started a game and were interrupted by a phone call. After the call you go back to the game and select quit.

When the phone call interrupts the activity: onPause(), onStop() The user then takes the phone call. When the user returns: onRestart(), onStart(), onResume() The user now again in the activity. When the user selects quit: onPause(), onStop(), onDestroy(). The activity is now fully shut down.

Why use XML based layouts?

XML based layouts are a good way to separate the "design" and "look" part of the app from the "logic" of the app found in the Java code. That way whenever you change something with the design in the XML, you know it won't logically affect the way the app behaves.

Are you able to force your app into a certain screen orientation? How or why not?

Yes. You can do this in your Manifest file by inserting an attribute in between the <activity </activity> lines. So, for example, if you want to force your app into landscape mode, you would insert the following into the activity section in your manifest: android:screenOrientation="landscape">

Suppose your app is not able to access the internet in the emulator. What could be the problem? You are 100% sure that your computer and other apps on the emulator have internet connection.

You maybe didn't set the proper permissions to allow the app to use the internet. To set proper permissions, paste the following into your manifest right below <manifest blahblah> line: <uses-permission android:name="android.permission.INTERNET"/>

What are two ways to implement a thread? How are these threads different from each other?

(1) Extend Thread. Declare a class by extending Thread and then override the run method of class Thread. An instance of the subclass can then be allocated and started. 2) Handler.

What are the two types of intent resolution? How are they different? Why use one of the other?

(1) explicit matching (direct intent). - specifies the recipient as one of the intent's component properties, by calling setComponent (ComponentName) or setClass (Context, Class) -the application notification starts the corresponding components. (2) implicit matching (indirect intent) - The recipient attribute is not specified in the component intent. - resolves to a single activity. Differences: For direct intent, Android does not need to do parsing because the target component is very clear. However, Android needs to resolve indirect intent.

Why is the manifest file the foundation for every Android App? Give at least four reasons.

1) Declares app's package name, the Android build tools use to determine the location of code entities when building your project. 2) Declares the permissions that the app needs to access protected parts of the system or other apps. 3) Declares the hardware and software features the app requires, which affects which devices can install the app from Google Play. 4) Declares the components of the app, which include all activities, services, broadcast receivers, and content providers.

You just created a project. The only thing you've done so far is add a ListView to the canvas. How do you populate the ListView using XML (2 step process)?

1) First you must go to your strings.xml file and create the array that you want to populate the ListView with. For example, let's say I want to fill a ListView with websites. I would go to my strings.xml and post this: <string-array name="websites"><item>http://www.google.com</item><item>http://www.netflix.com</item><item>www.hulu.com</item></string-array> 2) Then you have to populate the array in the xml in which the ListView is contained. You would do this by going to its attributes and giving a value to the android:entries attribute using the array like so: <ListViewandroid:entries="@array/websites"/>

What are the 2 ways that you can register a BroadcastReceiver? Give pseudocode.

1) Registering it in the Manifest file. We do this by naming the BroadcastReceiver's class/Java file with <receiver android:name="BlahBlah"> and then adding an intent filter with an action name inside of it that tells the BroadcastReceiver class to run depending on that specified action. Here's an example: <receiver android:name="MyBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.TIME_SET"/> </intent-filter> </receiver> 2) Registering it in the Java code programmatically. First you have to declare a BroadcastReceiver, with the type being the name of your BroadcastReceiver class. You then initialize it with a new instance of that class. Then you must make an IntentFilter object that is initialized with an IntentFilter that takes a specific keyword action into its constructor. Then you just registerReceiver(nameOfBroadcastReceiver, nameOfIntentFilter) and voila.

Suppose we have two threads that need to talk to each other (e.g. a thread reporting the progress of a download). Fill-in-the-blank. We create __________ to pass __________ back and forth.

1) a handler 2) messages

Consider the code below:<Button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button"android:text=""android:layout_width="fill_parent"android:layout_height="fill_parent"/> What does the '@' character do?

@ tells the XML parser to expand the rest of the id string and treat it as an ID resource.

Suppose you have more content to display than you have area on the screen. What type of View might you consider putting everything in?

A ScrollView.

Concerning Fragments, what should be returned in onCreateView() if you choose to implement this method?

A View. (this is done by returning the LayoutInflater that inflates the desired XML layout View)

What is a ViewFlipper? When would you want to use it?

A ViewFlipper is an object that is extended from ViewAnimator that basically transitions between 2 or more Views so that the user can look at different Views set up by the programmer. You can even specify the interval at which you want the Views to transition from one to the other. For example, if you wanted to make a nice photo compilation with music to go along with it (think graduation slideshow), you could have a bunch of ImageViews that change from one photo to the next every 5 seconds or so.

What is a Layout?

A layout is what specifically defines the structure that the appearance of the Activities in your app will have. Layouts are comprised of View and ViewGroup objects, the former which the user can see, and the latter which structurally manipulate those views. We can set different types of layouts, such as Relative, Linear, and Table, which accomplish different types of ways of viewing the material the developer wants the user to see.

What type of Layout does a WebView extend?

AbsoluteLayout

Name the four core components used in Android applications.

Activity, Content Provider, Services, and Broadcast Receiver.

What is an Activity?

An Activity is a class found in an Android app where the Android system initiates code. Not only does it initiate code, but each Activity usually has a specific purpose, or function, that lets you do things that tie into the purpose of the app as a whole. The Activity is also used as a canvas to draw the UI the original programmer intends for the app user to see and navigate with. Each Activity also represents a different screen that you see in the app, and by jumping from screen to screen within the app, you are essentially running through different Activities.

What is an Adapter? What is its purpose?

An Adapter is an object that essentially serves as a liaison between an AdapterView and data given in the Java code or the XML. Ultimately, it serves to populate a View with certain data. When an Adapter is created it takes in 3 parameters: the context, the type of layout of the View you want, and the data to transfer to the View. What you then do is take an existing View that supports the Adapter (specified by the 2nd parameter in the Adapter constructor), and you use the member function setAdapter(adapterName) and pass in the adapter. This populates your View with the data from the Adapter. For example, if you have a ListView called theView and do theView.setAdapter(adapterName), assuming we created an adapter of type CharSequence, it would make a list with the different strings that the adapter took in as a parameter.

What's the purpose of a BroadcastReceiver? Or describe a BroadcastReceiver.

BroadcastReceivers are classes that are set to run whenever specific actions occur that span across the whole device, not just the app (incoming SMS, email, etc.) They are registered either in the Manifest or in the Java code with Intent filters that determine what actions will trigger the broadcast. This is also its purpose; we want the BroadcastReceiver to wait for a certain action and run and perform actions every time that that specific action occurs so that our app can use incoming data to interact with the user and app itself.

<LinearLayout android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><View android:layout_height="0dip"android:layout_width="match_parent"android:layout_weight="2" /> <View android:layout_height="0dip"android:layout_width="match_parent"android:layout_weight="3" /> <View android:layout_height="0dip"android:layout_width="match_parent"android:layout_weight="5" /> </LinearLayout>

First, since it is a LinearLayout declared with a vertical orientation, the 3 child Views will be stacked on top of each other from top to bottom. Since the LinearLayout's height and width are both match parent, then the Layout itself encapsulates the whole screen. Since the 3 views match parent in regards to width, which is the LinearLayout View, they also are as wide as the screen. Since the heights of the Views are at 0, the layout_weight ultimately determines how tall they will be. Now with the weights of the 3 views, notice that they all add up to 10. So the 3rd view is of weight 5, for example, which is 5/10 in regards to the overall weight given in the Layout. This means that it will take up half (50%) of the screen, and since it is the last View given in the Layout, it will take up the bottom half. The one with a weight of 3 listed in the middle will take up 30% above the bottom one. Then the top one will take up the remaining 20% at the top.

What is the purpose of Fragments? Or, give an example of how Fragments can be useful.

Fragments are classes that can be used anywhere in order to display certain UIs/layouts within another Activity. This can be very useful in the sense that instead of reusing code/XML attributes in order to display a certain View, you can just use Fragments so that you can put it in different activities as much as you'd like without having to rewrite any preexisting code. It's very reusable and convenient in this sense.

When doing group projects, what is a good way to distribute source code with your teammates?

GitHub or Bitbucket

How do you pass data from one Activity A to another Activity B?

In Activity A, you would first create an Intent that is set to go to Activity B. Next you create a Bundle object. Once you create that Bundle object, you can use its member functions to store the data from Activity A into it using functions such as putString() or putInt(). You then call the Intent object's member function "putExtras(bundleName)" which takes in the Bundle you made in order to store that data from the Bundle into the Intent. Then you just startActivity(intentName) to go to Activity B. Now since you're in Activity B now, just create an Intent and assign getIntent() to it, then create a Bundle and assign it intentName.getExtras(); You can now get the data from the bundle using the get member functions.

Name an Android app that is amongst the Top 100 Free Apps in Google Play Store that uses a GridView. Explain why.

Instagram. The photos on someone's profile are organized into rows and columns that you can scroll through, which is defined as a GridView by the Android Developer websites.

Apps like FaceBook and WhatsApp allow you to communicate with people that are in your Android Device's contacts. For example, WhatsApp may scan your contacts to determine if any of your contacts are also using WhatsApp. You're trying to develop an app that works similar to WhatsApp. Unfortunately, your Java code that is supposed to read your contacts doesn't seem to work. In the scope of lecture 6, why doesn't it work, assuming that the problem is NOT with the Java code.

It could be that we do not have the correct permissions set in the Manifest file. In order to read contacts/access data outside of the app, we NEED permissions. So use: <uses-permission android:name="android.permission.READ_CONTACTS" />

What is LogCat? When would we use it? Why?

LogCat is a command-line tool/debugger that runs in Android Studio that shows the processes your app is running, stack traces, and even displays errors the app may be giving you. You definitely want to use it whenever your app is not working/crashing, or you get compiler errors. For example, if you call the String method startsWith() on a String that hasn't been initialized, your app may crash, so if you look in LogCat, it'll display why in red saying "null pointer exception" or something along those lines.

What is the difference between margin and padding?

Margins and paddings are both attributes that can be assigned to Views; however, they are different. Margins basically allocate space outside of the View to where other Views can only come within a certain distance of it. Paddings, however, can look similar to margins, except that the extra space you see outside of the visual component of the View is actually a part of the View itself.

Why should you use a @string resource for TextViews instead of hardcoding the string?

Not only is it good programming practice, but, for example, it allows us to update the use of a word throughout the whole code just by editing the @string xml file instead of having to do it one at a time, which would take much longer.

Name three layouts besides a LinearLayout.

RelativeLayout, TableLayout, and ConstraintLayout.

When dealing with the main process thread, what's the main issue to be concerned with? It's a big no no. What happens to the app and the user if we don't obey it?

Since the main process thread (also known as the UI thread) runs the majority of tasks by default, we want to make sure it mainly runs only UI components. This is because if we add a bunch of other tasks for it to handle, such as network access, it can majorly damage performance. That is why we should add other threads that deal with non-UI tasks so that the main thread has the power to deal with just the UI and making sure that the app runs smoothly overall.

Consider the code below:<Button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button"android:text=""android:layout_width="fill_parent"android:layout_height="fill_parent"/> What does the '+' character do?

The plus symbol, +, indicates that it's a new resource ID and the aapt tool will create a new resource integer in the R.java class, if it doesn't already exist.

Your screen was just rotated. How does this effect your Activity? What happens to your life cycle?

This actually causes the Activity to restart. This is because it must reload everything and use onCreate to place it accordingly. When it is rotated, onDestroy() is called to destroy the activity/current layout and onCreate() is then called to reconfigure the Activity according to the changes to the screen orientation.

What you happen to the data in your View when the screen was rotated? Any problems? How would they be fixed if they were?

This can sometimes result in a loss of data since it is reloading everything. What if you don't want to have your app's orientation locked? You must preserve the data another way. Data can be saved using (1) shared document-like data (typically via a content provider), or (2) an internal state (typically via user preferences).

What is a View?

Views are different objects that a programmer can use in Android Studio that make up the User Interface and allow the user to interact with the app itself. These Views, being subclasses of the View class itself, include many member functions that allow the programmer to modify them how they see it. Views can be just about anything you see on the app's screen; for example, a TextView is a subclass of the parent class "View" that can be used to allow the user to see, enter, and even edit text. Views even include more abstract UI components that you wouldn't realize are considered Views, such as different types of layouts, such as constrained and relative layouts.

Why use a RelativeLayout as opposed to a LinearLayout? Think about the View Hierarchy of more complex layouts. What is the major advantage you will get?

With a RelativeLayout, the major advantage is the overall performance. For example, with View Hierarchy, problems can arise whenever we have nested LinearLayouts inside of a LinearLayout. This is because whenever a Layout is formed, it executes measures each View and determines the size/position/etc. With LinearLayout, however, this has to be done twice if it's horizontal and sometimes when it's vertical, which costs us performance. This is called "double taxation." Whenever the LinearLayout is nested and nested, this just exponentially raises the performance cost. This does not happen with a RelativeLayout though.

How can you tell the system you don't want it's help with screen rotation? XML attribute? Method Implementation?

You can use the following attribute in the Manifest file: android:configChanges="orientation|screenSize|keyboardHidden"/> Method implementation: override onConfigurationChanged with: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED) OR setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)

If you want to center a view. Which attribute/property will you set?

You will set the gravity to center in the View's attributes in the XML, like so: android:gravity="center".

What is the significance of the "android.R"? What is it? Where? Why use it? Difference between just 'R'?

android.R (R meaning resources) is basically a reference to the resources that Android provides for you. This differs from just R in the sense that just R refers to the resources and data that you manually created in your XML files, whereas android.R refers to the enormous amount of data and resources inside of the Android library. For example, we would want to use it in an ArrayAdapter if we wanted to populate a ListView. Since the ArrayAdapter's 2nd parameter is a layout that determines the style in which our ListView is filled, we would use a predetermined layout from Android's Resources called "simple_list_item_1" that tailors to the ListView's specifications. Thanks to the android.R's resources, this is made a cinch and we don't have to do much else.


Related study sets

Adult final exam Nclex questions

View Set

25 Important Literary Terms for AP Lit

View Set

Chapter 2 - Achieving Strategic Fit and Scope

View Set