Const int SETSIZE = 30;



????? ????????? Philadelphia University ??? ???????: Paper Examination QFO-AP-FI-QA07????? ???????: ???? ????????? ????????? ??? ??????? :Revision) ) 1????? ???????: ????? ??????? ??????? ??? ????? ???????: 2 Lecturer: Dr. Samer Hanna Internal Examiner: Dr. Mohammad Taye First Semester of academic year: 2019-2020 Department of Software EngineeringCourse Name: Special Topics in SE (Android) 0721422 Date: Tuesday 07/01/2020Time: 50 min. Second ExamQ1. (10) Choose the correct answer1. C2. C3. A4. B5. B6. D7. D8. C9. B10. D1. During an Activity life-cycle, what is the first callback method invoked by the system? A. onStop( ) B. onStart( ) C. onCreate( ) D. onRestore( )2. What does the following line of code achieve? Intent intent = new Intent(FirstActivity.this, SecondActivity.class ); A. Creates a hidden Intent. B. Creates an implicit Intent. C. Create an explicit Intent. D. Starts an activity.3. What method you should override to use Android’s menu which is placed on the action bar? A. onCreateOptionsMenu() B. onCreateMenu() C. onMenuCreated() D. onMenuCreated()4. What Activity method you use to retrieve a reference to an Android view by using the id attribute of a resource XML? A. findViewByReference(int id) B. findViewById(int id) C. retrieveResourceById(int id) D. findViewById(String id)5. What does the Android project folder “res/” contain? A. Java Activity classes B. Resource files C. Java source code D. Libraries6. What does this code do? Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("")); startActivity(intent); A. Starts a sub-activity. B. Starts a service. C. Sends results to another activity. D. Starts an activity using an implicit intent.7. Which of the following lines of code is used to pass a value to the next activity? A. Intent i = new Intent(this,newActivity); i.addExtra(“test”); startActivity(i); B. Intent i = new Intent(this,newActivity); i.putValue(“test”); startActivity(i); C. Intent i = new Intent(this,newActivity); i.putValue(“value1”,“test”); startActivity(i); D. Intent i = new Intent(this,newActivity); i.putExtra(“value1”,“test”); startActivity(i);8. What is the parent class of all Activity widgets? A. ViewGroup B. Layout C. ViewD. Widget9. Which of the following best explains the Android context menus? A. It is a popup menu displays a list of items in a vertical list that's anchored to the view that invoked the menu. B. It is a floating menu that appears when the user performs a long-click on an element. It provides actions that affect the selected content or context frame. C. It is the primary collection of menu items for an activity. It's where you should place actions that have a global impact on the app, such as "Search," "Compose email," and "Settings". D. It is a sub-menu of an options menu item.10. Which of these files contains text values that you can use in your application? A. AndroidManifest.xml B. res/Text.xml C.res/layout/Main.xml D. res/values/strings.xmlQ2. (5) marksFor the Alert Dialogue below:Write the Java code that show this alert where, the Yes button exit from an activity and the No button just cancel the alert dialogue.Solution:package com.example.alertapp;..public class MainActivity extends AppCompatActivity { Button btn_alert; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_alert = (Button) findViewById(R.id.btn_alert); btn_alert.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this); // 1 mark alert.setTitle("Exit"); alert.setMessage("Are you sure ?"); // 1 mark alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } });// 1 mark alert.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } });// 1 mark alert.setCancelable(false); alert.show();// 1 mark } }); }}Q3. (5) marksFor the following activity:1. Write a brief of the XML layout file for this activity (2 marks)2. Write a Java code to show a Toast message that contains the user selection. (3 marks)Solution:1.<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="" xmlns:app="" xmlns:tools="" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <RadioGroup android:id="@+id/rg_marital" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="24dp" android:layout_marginLeft="24dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <RadioButton android:id="@+id/rb_single" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Single" /> <RadioButton android:id="@+id/rb_married" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Married" /> <RadioButton android:id="@+id/rb_divorced" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Divorced" /> </RadioGroup> <Button android:id="@+id/btn_show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="24dp" android:layout_marginLeft="24dp" android:layout_marginTop="92dp" android:layout_marginEnd="24dp" android:layout_marginRight="24dp" android:text="Ok" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.545" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/rg_marital" /></androidx.constraintlayout.widget.ConstraintLayout>2.package com.example.radiobutton;…public class MainActivity extends AppCompatActivity { RadioGroup rg_marital; RadioButton checked; Button btn_show; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_show = (Button) findViewById(R.id.btn_show); btn_show.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { rg_marital = (RadioGroup) findViewById(R.id.rg_marital); int sel = rg_marital.getCheckedRadioButtonId(); checked = (RadioButton) findViewById(sel); Toast.makeText(MainActivity.this, checked.getText().toString(), Toast.LENGTH_SHORT).show(); } }); }} ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download