0% found this document useful (0 votes)
14 views16 pages

Student Info Management App Development

The document outlines the development of various Android applications, including a student information app, a fragment-based UI app, a customer management app using SharedPreferences, and a music playback service. It provides code examples for sending and receiving data between activities, saving data to a database, and implementing background tasks. Additionally, it describes Android resources such as strings.xml, colors.xml, and permissions needed for SMS functionality.

Uploaded by

gozbethnyasio
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views16 pages

Student Info Management App Development

The document outlines the development of various Android applications, including a student information app, a fragment-based UI app, a customer management app using SharedPreferences, and a music playback service. It provides code examples for sending and receiving data between activities, saving data to a database, and implementing background tasks. Additionally, it describes Android resources such as strings.xml, colors.xml, and permissions needed for SMS functionality.

Uploaded by

gozbethnyasio
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

You have been asked by the management of Dodoma Secondary School to develop a mobile

application that will store the information of the students. The app should store name, region, age,
gender and subjects of the student. The management want to show the reports of how the student
performs his/her subjects (English, Mathematics, Physics, Chemistry and Biology). The management
also wants to show the dates of different events within the school. The management suggests the
following features to be used: radio button for gender, spinner for region, and checkboxes for
subjects. Use progress bar to show the performance of the students and calendar to show the dates
of the events. Based on the given requirements, you found that the application has only two
activities i.e. ActivityOne and ActivityTwo.

a. Using the methods of Intent class show how you will send the student's data to the second
activity.

b. Using the methods of Intent class show how you will receive the student's data within the second
activity.

c. By the help of SQLiteOpenHelper class, show how you can save the student's details in a database.
Use user and student as the name of the database and table respectively.

a. To send the student's data to the second activity using Intent, you can use the putExtra method.
For example:

Copy code

Intent intent = new Intent([Link], [Link]);

[Link]("name", studentName);

[Link]("region", studentRegion);

[Link]("age", studentAge);

[Link]("gender", studentGender);

[Link]("subjects", studentSubjects);

startActivity(intent);

b. To receive the student's data within the second activity, you can use the getStringExtra,
getIntExtra, etc. method within the onCreate method of the second activity. For example:

Copy code

String studentName = getIntent().getStringExtra("name");

String studentRegion = getIntent().getStringExtra("region");

int studentAge = getIntent().getIntExtra("age", 0);

String studentGender = getIntent().getStringExtra("gender");

String studentSubjects = getIntent().getStringExtra("subjects");


c. To save the student's details in a database using SQLiteOpenHelper class, you need to create a
class that extends SQLiteOpenHelper.

Copy code

public class DatabaseHelper extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "[Link]";

public static final String TABLE_NAME = "student";

public static final String COL_1 = "ID";

public static final String COL_2 = "NAME";

public static final String COL_3 = "REGION";

public static final String COL_4 = "AGE";

public static final String COL_5 = "GENDER";

public static final String COL_6 = "SUBJECTS";

public DatabaseHelper(Context context) {

super(context, DATABASE_NAME, null, 1);

@Override

public void onCreate(SQLiteDatabase db) {

[Link]("CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT,
NAME TEXT, REGION TEXT, AGE INTEGER, GENDER TEXT, SUBJECTS TEXT)");

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);

onCreate(db);

public boolean insertData(String name, String region, String age, String gender, String subjects) {

SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();

[Link](COL_2, name);

[Link](COL_3, region);

[Link](COL_4, age);

[Link](COL_5, gender);

[Link](COL_6, subjects);

long result = [Link](TABLE_NAME, null, contentValues);

if (result == -1)

return false;

else

return true;

You can then call the insertData method in your ActivityOne to save the student's data to the
database.

DatabaseHelper dbHelper = new DatabaseHelper(this);

boolean insertSuccess = [Link](studentName, studentRegion, studentAge,


studentGender, studentSubjects);

if(insertSuccess){

// show success message

}else{

// show failure message

This will insert the student's data into the student table of the user database, and you can then
retrieve the data for reporting or other purposes
Android Fragment represents a behavior or a portion of a user interface in an activity. Multiple
fragments can be combined in a single activity to build a multi-panel User Interface (UI) and reuse a
fragment in multiple activities. As a mobile apps developer, you have been asked to develop an
application with two fragments named FragmentOne and FragmentTwo. When a user click on the
specific fragment, the description of the fragment displays on the fragment container in the main
activity which hosts the fragments. Assume the ids for FragmentOne and FragmentTwo are
btnFragment one and btnFragment two respectively. Hint: use linear layout to create a fragment
container

To develop an application with two fragments named FragmentOne and FragmentTwo, you can
follow these steps:

Create two new fragments, FragmentOne and FragmentTwo, by extending the Fragment class and
overriding the onCreateView method. In the onCreateView method, you can inflate the layout for
the fragment and return the view.

Copy code

public class FragmentOne extends Fragment {

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

// Inflate the layout for this fragment

return [Link]([Link].fragment_one, container, false);

Create a LinearLayout as a fragment container in your main activity's layout file. This layout will be
used to display the selected fragment.

Copy code

<LinearLayout

android:id="@+id/fragment_container"

android:layout_width="match_parent"

android:layout_height="match_parent">

</LinearLayout>

In your main activity's onCreate method, set onClickListeners for the buttons that correspond to
FragmentOne and FragmentTwo. In the onClick method for each button, you can create a new
instance of the corresponding fragment and use the FragmentManager and FragmentTransaction to
replace the current fragment in the fragment container with the selected fragment.

Copy code
public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

Button btnFragmentOne = findViewById([Link]);

[Link](new [Link]() {

@Override

public void onClick(View view) {

FragmentOne fragment = new FragmentOne();

FragmentManager fragmentManager = getSupportFragmentManager();

FragmentTransaction fragmentTransaction = [Link]();

[Link]([Link].fragment_container, fragment);

[Link]();

});

Button btnFragmentTwo = findViewById([Link]);

[Link](new [Link]() {

@Override

public void onClick(View view) {

FragmentTwo fragment = new FragmentTwo();

FragmentManager fragmentManager = getSupportFragmentManager();

FragmentTransaction fragmentTransaction = [Link]();

[Link]([Link].fragment_container, fragment);

[Link]();

});

}
When the user clicks on the specific fragment button, the description of the fragment will display on
the fragment container in the main activity which hosts the fragments.
The management of CIVE cafeteria wants to implement an android system that will manage its
customers. The application has only one activity named MainActivity with three edit texts and one
button. One of the functionality of the application is to store the customer's information such as
name, email and phone number. The customer's data are in small amount and are in key value pairs.
Write an android application that will store the customer's information in a Shared Preference The
ids for the edit texts and button are etName, etEmail, etPhoneNumber and btnSave

To create an android application that stores customer's information in a SharedPreference, you can
follow these steps:

In the MainActivity's onCreate method, get an instance of the SharedPreference by calling the
getSharedPreferences method.

Copy code

SharedPreferences sharedPreferences = getSharedPreferences("customer_data", MODE_PRIVATE);

In the layout file of MainActivity, add three EditText views for name, email, and phone number, and
one button for saving the data.

Copy code

<LinearLayout>

<EditText

android:id="@+id/etName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Name" />

<EditText

android:id="@+id/etEmail"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Email" />

<EditText

android:id="@+id/etPhoneNumber"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Phone Number" />


<Button

android:id="@+id/btnSave"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Save" />

</LinearLayout>

In the MainActivity class, set an onClickListener for the save button. In the onClick method, you can
get the text from the EditText views, and use the putString method of the [Link]
to store the data in the SharedPreference.

Copy code

Button btnSave = findViewById([Link]);

[Link](new [Link]() {

@Override

public void onClick(View v) {

EditText etName = findViewById([Link]);

EditText etEmail = findViewById([Link]);

EditText etPhoneNumber = findViewById([Link]);

String name = [Link]().toString();

String email = [Link]().toString();

String phoneNumber = [Link]().toString();

[Link] editor = [Link]();

[Link]("name", name);

[Link]("email", email);

[Link]("phoneNumber", phoneNumber);

[Link]();

[Link]([Link], "Data Saved", Toast.LENGTH_SHORT).show();

});
With this implementation, the customer's data will be stored in the SharedPreference and can be
accessed by other applications that have the same package name. You can also retrieve the data by
calling the getString method of the SharedPreference and passing in the key.

String name = [Link]("name", "");

String email = [Link]("email", "");

String phoneNumber = [Link]("phoneNumber", "");


There are tasks that do not really need to be visible to the user.

A good example is playing a music. You don't need to keep the player's screen for song to play.
Those kinds of applications/tasks runs in the background.

i. Suggests the kind of android component that you can use to accomplish such kind of task.

ii. Based on your suggestion in part (i), write a java class to implement a task for playing music.
Assume the music you want to play is located at [Link].DEFAULT_RINGTONE_URI

i. To accomplish a task that runs in the background such as playing music, you can use a Service
component in android. A Service is a component that runs in the background, independently of the
activity lifecycle and can perform long-running operations.

ii. Here is an example of a Java class that implements a task for playing music using a Service
component:

Copy code

public class MusicService extends Service {

private MediaPlayer mediaPlayer;

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

Uri uri = [Link].DEFAULT_RINGTONE_URI;

mediaPlayer = [Link](this, uri);

[Link]();

return [Link](intent, flags, startId);

@Override

public void onDestroy() {

[Link]();

[Link]();

@Nullable

@Override
public IBinder onBind(Intent intent) {

return null;

In this example, the MusicService class extends the Service class, and overrides the
onStartCommand method. The MediaPlayer class is used to play the music, and the create method is
used to create the MediaPlayer with the URI of the music file. The start method is used to start
playing the music, and the stop method is used to stop the music when the service is destroyed.

To start the service, you can use the startService method, passing in an intent that contains the
context and the class of the service.

Copy code

Intent serviceIntent = new Intent(this, [Link]);

startService(serviceIntent);

To stop the service, you can use the stopService method and pass in the same intent.

Copy code

stopService(serviceIntent);
With examples, briefly provide the explanation of the following features:-

a. [Link]

b. [Link]

c. Android Virtual Device (AVD) d. TOAST

c. View

a. [Link] is an XML file located in the res/values folder of an Android project. It is used to store
string resources that can be accessed from the Java code. String resources can include text for labels,
buttons, and other UI elements, as well as text for messages and other application-specific strings.
This allows for easy localization and management of strings in the application.

For example, you can define a string in [Link]:

Copy code

<string name="hello_world">Hello World!</string>

and then you can access it in your Java code like this:

Copy code

String message = getString([Link].hello_world);

b. [Link] is an XML file located in the res/values folder of an Android project. It is used to store
color resources that can be accessed from the Java code or XML layout files. This allows for easy
management of colors in the application.

For example, you can define a color in [Link]:

Copy code

<color name="colorPrimary">#3F51B5</color>

and then you can access it in your Java code like this:

Copy code
int color = getResources().getColor([Link]);

c. Android Virtual Device (AVD) is an emulator that allows developers to test and run their Android
applications on different devices and configurations without the need for physical devices.
Developers can use AVD Manager to create, configure and run virtual devices that emulate different
versions of Android and different hardware configurations.

d. TOAST is a view that can be used to display a simple message or notification to the user. Toasts
are displayed on the screen for a short period of time and automatically disappear. They can be used
to display messages such as "Data saved" or "No Internet connection". Toasts can be created and
displayed in the code using the Toast class, and the makeText method.

For example, you can display a toast in your Java code like this:

Copy code

[Link](this, "Data saved", Toast.LENGTH_SHORT).show();

e. View is the base class for all UI components in Android. It represents the basic building block for
user interface components such as buttons, text fields, and images. View provides the basic layout
and drawing mechanisms, and can be extended to create custom UI components. The Android
framework provides a number of subclasses of the View class, such as TextView, Button, and
ImageView, that can be used to create common UI elements.
Name the two permissions you need to declare in your [Link] file for sending and
receiving SMS messages.

The two permissions you need to declare in your [Link] file for sending and receiving
SMS messages are:

[Link].SEND_SMS: This permission is required to send SMS messages.

[Link].RECEIVE_SMS: This permission is required to receive SMS messages.

You can declare these permissions in your [Link] file like this:

Copy code

<manifest>

<uses-permission android:name="[Link].SEND_SMS" />

<uses-permission android:name="[Link].RECEIVE_SMS" />

...

</manifest>
Provide a brief description of the following android project resources: -

(1 Mark Each)

a. res/mipmap

b. Gradle

c. res/drawable

d. Menu

e. Manisfests/

a. res/mipmap: The mipmap folder is used to store app icons in different resolutions. The icons
stored in this folder are used for different screen densities, and it is recommended to use this folder
instead of the res/drawable folder for app icons.

b. Gradle: Gradle is a build automation tool that is used to manage the dependencies and build
process of an Android project. It is used to define the project structure, dependencies, and tasks that
need to be executed in order to build and deploy the app. It also makes it easy to manage and
update dependencies, and automate tasks such as building, testing and deploying.

c. res/drawable: The drawable folder is used to store images and other drawable resources for an
Android project. These resources can include images, shapes, and XML files that define custom
graphics. The images stored in this folder can be used in the layout files, or accessed in the code.

d. Menu: The menu is a resource that defines the options available to the user in an Android app.
Menus are typically displayed in an app bar or action bar, and can include options such as settings,
search, and other actions. Menus can be created using XML files, and can be accessed and
manipulated in the code using the Menu and MenuItem classes.

e. Manifests: The manifests folder contains the [Link] file, which is a central
configuration file for an Android project. This file contains important information about the app such
as the package name, the minimum required SDK, the app's main activity, and the permissions
required by the app. This file also contains the declarations of all the activities, services, broadcast
receivers and content providers of the app.
Implicit Intents are used when you want to perform an action and you don't know which component
should handle it, while Explicit Intents are used when you want to perform an action and you know
which component should handle it.

Explicit

Intent intent = new Intent(this, [Link]);

startActivity(intent);

Implicit

Intent intent = new Intent(Intent.ACTION_VIEW);

[Link]([Link]("[Link]

startActivity(intent);

onPause() method is used to save the current state of an activity before it is closed or obscured,
while the onSaveInstanceState() method is used to save the current state of an activity before it is
destroyed in order to restore it when the activity is recreated.

Common questions

Powered by AI

Implementing conditional UI display using fragments involves creating separate fragment classes for each UI component. For instance, develop `FragmentOne` and `FragmentTwo` by extending the `Fragment` class and overriding the `onCreateView` method to inflate respective layouts . In the main activity layout, use a `LinearLayout` as a container for these fragments. Set `OnClickListeners` for buttons corresponding to each fragment. When a button is clicked, use `FragmentManager` and `FragmentTransaction` to replace the current display with the selected fragment by invoking `replace()` on the fragment container . This pattern allows dynamic UI updates without needing to reload or recreate the entire activity, ensuring a smooth user experience. Additionally, the modular approach facilitates reusability and flexibility in complex UIs .

Android's Intent system is pivotal for inter-component communication, allowing different app parts or even separate applications to interact. Intents can be explicit or implicit, as defined by the context of the interaction. Explicit intents specify a target component, ensuring direct interaction within the app, such as launching a new activity with `Intent intent = new Intent(this, TargetActivity.class); startActivity(intent);` . This guarantees precise communication paths known during development. Conversely, implicit intents declare a general action to be performed, relying on the system to find an appropriate component, as seen in web browsing where `Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); startActivity(intent);` might open a default browser . This flexibility permits seamless, efficient cross-application communication, enabling features like content sharing among various apps while preserving user autonomy in choosing action-handling components .

To create a mobile application for managing student data, you follow these steps: 1) Design the user interface with components like radio buttons for gender selection, spinners for region, and checkboxes for subjects, as stated in the requirements. A progress bar is used to display students' performance and a calendar for event dates . 2) Develop activities and fragments, making use of Intents to pass data between activities. Implement methods like `putExtra` to send data and `getStringExtra` to receive it . 3) Establish a database using `SQLiteOpenHelper` to store and manage student data securely. Create tables such as 'student' with columns for ID, name, region, age, gender, and subjects, and implement CRUD operations like `insertData` for data entry . 4) Integrate progress tracking and reporting functionalities by utilizing the stored data to calculate and display student performance metrics. Generate reports comparing subjects' performance using stored data and present them visually using the progress bar .

XML resource files in Android are used to manage UI components and configurations efficiently. The `strings.xml` file stores all string literals, which allows easy localization and management of UI text. For example, defining strings in `strings.xml` like `<string name="hello_world">Hello World!</string>` allows access in Java code and XML layouts . The `colors.xml` file, similarly, holds definitions of color resources, permitting centralized control over color properties used throughout the app. Colors defined here, like `<color name="colorPrimary">#3F51B5</color>`, can be easily referenced in layouts or Java code . These practices promote cleaner code, easier maintenance, and localization by avoiding hard-coded values .

Background music playback in an Android app involves using a Service component, which allows tasks to run independently of the UI lifecycle. Implement a `Service` class like `MusicService` that overrides the `onStartCommand` method. Use `MediaPlayer` to handle music playback, initializing it with a URI, such as `Settings.System.DEFAULT_RINGTONE_URI`, and start the player within the `onStartCommand` method. Ensure media resources are properly managed by stopping the player in `onDestroy`. To control the service lifecycle, utilize `startService` to begin and `stopService` to terminate the service with intents . Assign appropriate permissions in the manifest for accessing device audio files to ensure functionality across different Android versions .

Implicit and explicit intents serve different purposes in Android apps. Explicit intents directly specify the component to be called, using the component's class name, making them suitable for in-app component communication. For instance, starting a known activity, like `SecondActivity`, is done using `new Intent(this, SecondActivity.class)` followed by `startActivity(intent)` . In contrast, implicit intents do not specify a component; instead, they declare an action to be performed, allowing any app component capable of completing that action to do so. This is useful for actions like opening a web page with `new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"))`, leaving the choice of an appropriate app to the system based on available handlers . This design enables broader functionality and integration across different apps while maintaining specific control within an app’s context (explicit).

Using `SQLiteOpenHelper` streamlines the management of databases within Android apps by handling database creation and version management. To utilize it for a student database, extend the SQLiteOpenHelper class and override the `onCreate` and `onUpgrade` methods. In `onCreate`, execute SQL commands to create necessary database tables, like the 'student' table with columns for IDs, names, regions, ages, genders, and subjects; use SQL `CREATE TABLE` statements for this . Implement CRUD operations—use `SQLiteDatabase` methods like `insert`, `update`, `delete`, and `query` to manage records . Call methods like `getWritableDatabase()` and `getReadableDatabase()` to open the database for writing or reading operations. This approach helps maintain data integrity and consistency while managing database versioning seamlessly, making updates non-intrusive .

Fragments provide modularity and flexibility by enabling UI components to be divided into manageable pieces within activities, promoting reuse and dynamic layout changes. To implement fragments, first create a class extending the `Fragment` base class and override the `onCreateView` method to inflate the UI layout specific to each fragment . Include a `LinearLayout` in your activity as a fragment container. In the main activity, define click listeners for buttons or UI controls to select fragments. Use `FragmentManager` and `FragmentTransaction` to replace the current fragment in the container through methods like `replace()` and `commit()` . Fragments can dynamically alter the UI by replacing or adding entire sections within an activity, making applications responsive to varying device configurations and user interactions. Their lifecycle differs from activities, providing more control over UI changes without disrupting the activity itself .

The AndroidManifest.xml file serves as the central configuration for an Android application, defining essential information like package name, components, permissions, and intent filters. It declares all the activities, services, broadcast receivers, and content providers that the app will use, guiding the Android system on their lifecycle management. For example, permissions such as `android.permission.SEND_SMS` and `android.permission.RECEIVE_SMS` are specified here to enable SMS functionalities . The manifest also defines critical attributes such as the app’s minimum SDK requirements and main activity, setting up the necessary environment for the app to function correctly within the Android ecosystem . This file ensures that all interactions and permissions are handled securely and appropriately with respect to Android OS policies and user privacy .

Efficient management of customer information in an Android app can be achieved through SharedPreferences for lightweight data storage. First, instantiate `SharedPreferences` in the `MainActivity` using `getSharedPreferences("customer_data", MODE_PRIVATE)`. Design the UI with EditTexts for entering name, email, and phone numbers, and a button to save the data. Implement an `OnClickListener` for the button to capture user input from EditText views and store them using `SharedPreferences.Editor`, employing methods like `putString` to save the data. Finally, use `apply()` to commit changes to SharedPreferences . This method ensures easy retrieval of small amounts of data in key-value pairs without complex database operations .

You might also like