You are on page 1of 6

Kingdom of Saudi Arabia

Ministry of Education
Prince Sattam Bin Abdulaziz University ‫وزارة التعليم‬
College of Computer ‫جامعة االمير سطام بن عبد العزيز‬
Engineering and sciences ‫كلية هندسة وعلوم الحاسب‬
Department of Computer Sciences
‫قسم علوم الحاسب‬
Course Title and Code: Mobile Applications
:‫اسم الطالبة‬
development CS4831
Second Exam
Instructor Name: Dr. Ahmed Ghneimat
Semester I :‫الرقم الجامعي‬
Dr Aisha Abuduulahi
1439/1440
Date: 05-03-1440 H
:‫رقم الشعبة‬
Time: 60 minutes

Instructions ‫تعليمات‬
▪ This exam consists of (2) questions on 3 pages. ‫ صفحات‬3 ‫) أسئلة على‬2( ‫هذا االختبار مؤلف من‬ ▪
▪ All questions should be answered on the same sheets
▪ Electronic devices that could have a memory is not
‫جاوب على جميع األسئلة على نفس االوراق‬ ▪
allowed for theoretical part ‫يمنع استعمال االجهزة االلكترونية التي تحتوي على ذاكرة‬ ▪
▪ Traditional calculator is allowed ‫للجزء النظري‬
▪ Examination rules must be adhered. )‫يسمح باستعمال االلة الحاسبة (دون ذاكرة‬ ▪
● Books or other related materials are NOT allowed
.‫يجب االلتزام بجميع قوانين ولوائح االمتحانات‬ ▪
● Use blue pen only
‫ال يسمح بالكتب أو المواد ذات الصلة داخل غرفة االمتحان‬ ▪
‫الكتابة تكون بالقلم األزرق فقط‬ ▪

Mobile Applications Development Second Exam - 1439-1440(First Semester)Page: 1 of 6


Q1 ) – (5 Marks)
a- Choose the most appropriate answer

1. For an activity that has the following intent-filter,


<intent-filter>
<action android:name=”android.intent.action.SEND”/>
<action android:name=”android.intent.action.VIEW”/>
<category android:name=”android.intent.category.DEFAULT”/>
<data android:mimeType=”text/*”/>
</intent-filter>

Which of the following intents should pass this filter?


1) Intent intent = new Intent(Intent.ACTION_DIAL);
2) Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); and
3) Intent intent = new Intent();

2. The utilities of using android resources are


a) Separate between data presentation and data management
b) Provide alternative resources to support different device specifications
c) Force a recompile whenever a new device is supported
d) a & b

3. To access a string resource called ‘day’, in a package that’s called android in java
a) R.android.string.day
b) String.android.R.day
c) android@R.string.day
d) android.R.string.day

4. A single intent definition may contain


a) Component Name with a flag, and data.
b) Data, category, and extra.
c) Action and data and the component name
d) An action, data and extras

5. RESULT_OK, means that ..


a) The click event is successfully executed
b) The intent has successfully returned the requested results
c) The drawable has been successfully displayed
d) a & b

b- Match the terms from the numbered column with statements in the second
1. R class 5 Used as an Alias to raw image files, and to specify additional properties
too
2. Explicit intents 3 Has a set of attributes to apply on a specific UI component
3. Style 6 Launch an activity expecting results upon its closure
4. onActivityResult 1 Automatically generated file, recreated if res/ directory is modified
5. XMLBitmap 2 Controls the application flow between activities in the same application
6. startActivityForResult 4 Used to handle the results sent from second activity

Mobile Applications Development Second Exam - 1439-1440(First Semester)Page: 2 of 6


Q2 Develop an application to the following specifications:
Design and write an android application that enables a simplified chatting between two activities. The first
activity sends messages to the second, and the second responds to these messages.

a) The activities design must be like the ones in the figure 1 (4 marks)
Set the application name to Chat Application
Define all the labels in the app as resources.
b) In the first activity (left), if the user clicks the ‘send’ button, the text in the edit text must be sent
to the second activity. (3 marks)

c) In the second activity: (3 marks)


o If the user clicks ‘answer’, the text in the edit text must be sent back to the first activity.
o If the user clicks ‘share’, an intent with ACTION_SEND must be issued, which enables the
user to share the received text through a list of other applications installed on the device

Note Copy the XML and Java file for each activity and upload it to the blackboard
Eaxm2

Mobile Applications Development Second Exam - 1439-1440(First Semester)Page: 3 of 6


string.xml

<resources>
<string name="app_name">ChatApplication</string>
<string name="send">Send</string>
<string name="textInit">Nothing is sent yet</string>
<string name="editHint">Enter your message here .. </string>
<string name="answer">Answer</string>
<string name="share">Share</string>
</resources>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.satalites55.chatapplication.MainActivity">

<TextView
android:id="@+id/received"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textInit"
/>
<EditText
android:id="@+id/sender"
android:hint="@string/editHint"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/send"
android:text="@string/send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="send"/>

</LinearLayout>

MainActivity.java

package com.example.satalites55.chatapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


EditText editText;
TextView textView;
public static final int REQUEST_CODE = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.sender);
textView = findViewById(R.id.received);

Mobile Applications Development Second Exam - 1439-1440(First Semester)Page: 4 of 6


}

public void send(View v){


Intent intent = new Intent(this, Main2Activity.class);
String sent = editText.getText().toString();
intent.putExtra("sender", sent);
startActivityForResult(intent, REQUEST_CODE);
}

public void onActivityResult(int requestCode, int resultCode, Intent data){


String received= data.getExtras().getString("receiver");
textView.setText(received);
editText.setText("");
}
}

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.satalites55.chatapplication.Main2Activity">

<TextView
android:id="@+id/sent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<EditText
android:id="@+id/receiver"
android:hint="@string/editHint"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="answer"
android:text="@string/answer" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="share"
android:text="@string/share" />

</LinearLayout>

Main2Activity.xml
package com.example.satalites55.chatapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class Main2Activity extends AppCompatActivity {


EditText editText;

Mobile Applications Development Second Exam - 1439-1440(First Semester)Page: 5 of 6


TextView textView;
String sender;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
editText = findViewById(R.id.receiver);
textView = findViewById(R.id.sent);
Intent intent = getIntent();
sender = intent.getExtras().getString("sender");
textView.setText(sender);
}

public void answer(View v) {


Intent intent = new Intent();
setResult(RESULT_OK, intent);
String answer = editText.getText().toString();
intent.putExtra("receiver", answer);
finish();

public void share(View v) {


Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, sender);
shareIntent.setType("text/plain");
if (shareIntent.resolveActivity(getPackageManager()) != null)
startActivity(shareIntent);
}
}

Mobile Applications Development Second Exam - 1439-1440(First Semester)Page: 6 of 6

You might also like