0% found this document useful (0 votes)
19 views

Android Questions

The document provides code snippets and explanations for different Android concepts and problems. The summary is: 1) The code checks if a device has a compass sensor by checking the sensor manager for the compass feature. 2) The XML layout defines an edit text to the left of a text view and a button beneath them. 3) Starting a long-running operation on a new thread in an activity's onCreate could cause a memory leak if the user leaves the activity first.

Uploaded by

Shreya Jain
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Android Questions

The document provides code snippets and explanations for different Android concepts and problems. The summary is: 1) The code checks if a device has a compass sensor by checking the sensor manager for the compass feature. 2) The XML layout defines an edit text to the left of a text view and a button beneath them. 3) Starting a long-running operation on a new thread in an activity's onCreate could cause a memory leak if the user leaves the activity first.

Uploaded by

Shreya Jain
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Section Problem Statement Option 1

PackageManager m =
getPackageManager();
if (!
m.hasSystemFeature(Package
Manager.FEATURE_SENSO
R_COMPASS)) {
// This device does not have
Which of the code snippets below is the a compass, turn off the
correct way to check if a Compass compass feature
Android sensor is present on the system? }
_______ provides support for Hyper
Text Transfer Protocol (HTTP) org.apache.hhttp.*
Broadcast that includes information android.intent.action.BATTER
about battery state, level, etc. is Y_LOW

Consider the following code :


@Override public void
onCreateContextMenu(ContextMenu
menu, View v, ContextMenuInfo
menuInfo)
{ super.onCreateContextMenu(menu, v,
menuInfo);
menu.setHeaderTitle("Menu");
AdapterContextMenuInfo cmi =
(AdapterContextMenuInfo) menuInfo;
menu.add(1, cmi.position, 0, "Open
file"); menu.add(2, cmi.position, 0,
"Save file"); }

Which of the following best explains the The code inflates an xml file
code above? into menu items
<?xml version="1.0" encoding="utf-8"?
>
<LinearLayout
xmlns:android="http://schemas.android.
com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Post" /> An edit text to the left of a text
</LinearLayout> view and a button beneath it.
What is potentially wrong with the
following Android code?

public class MainActivity extends


AppCompatActivity {
@Override
protected void onCreate(@Nullable final
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Thread() {
@Override
public void run() {
//Super long-running operation}
}.start(); MainActivity will be leaked if
} the user leaves the activity
} before the long operation is
complete.
Option 2 Option 3 (Optional) Option 4 (Optional)

SensorManager m =
getSensorManager(); Sensor s = getSensor();
if (! if (!
m.hasSystemFeature(SensorM s.hasSystemFeature(Sensor.FE
anager.FEATURE_SENSOR_ ATURE_SENSOR_COMPAS
COMPASS)) { S)) {
// This device does not have // This device does not have
a compass, turn off the a compass, turn off the
compass feature compass feature
} } None of these

org.support.http.* org.apache.http.* None of these


android.intent.action.BATTER android.intent.action.BATTER android.intent.action.CALL_B
Y_CHANGED Y_OKAY UTTON

The code creates menu items The code Opens a menu


for context menu The code assign actions to resource file, modifies it, and
programmatically. menu items. saves the changes.
An edit text to the right of a An edit text to the right of a A text view, an edit text
text view and a button to the text view and a button beneath beneath it and the button
right of the text view them beneath the edit text
You cannot start a new thread The Bundle
from the onCreate() of an savedInstanceState cannot be The Thread created will lock
activity Nullable. up the Android application.
Correct Option

2
3
1

You might also like