Android Activities Overview

LuckierChiasmus avatar
LuckierChiasmus
·
·
Download

Start Quiz

Study Flashcards

30 Questions

What is the purpose of the Activity class in Android?

Each screen your user interacts with is typically represented by an activity.

Describe the content of an Activity in Android.

Every activity contains the layout, which has a user interface to interact with the user.

What method in an Android Activity is called when the activity is first created?

onCreate

When is the onStart method called in the activity life cycle?

when activity is becoming visible to the user

Which method is invoked when the activity is not visible to the user?

onPause

What is the method called before the activity is destroyed?

onDestroy

What is the purpose of the Context.startActivity() method in Android?

To launch a new activity or get an existing activity to perform an action

What is the main difference between Implicit Intent and Explicit Intent in Android?

Implicit Intent provides a generic action and can be handled by any app that matches the criteria, while Explicit Intent fulfills a request using a specific component

What is the purpose of the Context.sendBroadcast() method in Android?

To deliver a message to broadcast receivers

In Android, what is the purpose of Services?

To facilitate an application to run in the background to perform long-running operation tasks

What is the syntax for creating an Implicit Intent in Android?

Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://www.geeksforgeeks.org/")); startActivity(intent);

What is the syntax for creating an Explicit Intent in Android?

Intent i = new Intent(getApplicationContext(), ActivityTwo.class); startActivity(i);

What is the main objective of an Android service?

To ensure that the application remains active in the background so that the user can operate multiple applications at the same time.

What type of Android service notifies the user about its ongoing operations?

Foreground Services

How can the execution of a Started Service be stopped?

By calling stopService() method or the service can stop itself by using stopSelf() method.

What is required for a service to be termed as bounded?

An application component binds itself with a service by calling bindService() method.

How can the execution of a Bounded Service be stopped?

All the components must unbind themselves from the service by using unbindService() method.

What type of service does not require any user intervention?

Background Services

What is the primary purpose of using Bundle in Android?

Passing data from one activity to another

What type of data can be stored in a Bundle?

All types of values (int, String, boolean, char)

How is data retrieved from a Bundle in the receiving activity?

Using getIntent().getExtras() and getString(key, default_value)

What are some examples of when multiple activities are used in an app?

Viewing details of a single item, creating a new item, showing settings, and accessing services in other apps

What is the purpose of an Intent in Android?

A messaging object that passes between components

How is a Bundle passed to an Intent?

Using Intent.putExtras(Bundle)

In which lifecycle method should you perform app startup logic and inflate the UI?

You should perform app startup logic and inflate the UI in the onCreate() method.

What happens in the onResume() lifecycle method, and what is its counterpart?

The onResume() method allows the activity to gain input focus, enabling the user to interact with the activity. The activity remains in the resumed state until the system triggers it to be paused. Its counterpart is the onPause() method.

What is the purpose of the onStop() lifecycle method, and what should be done in this method?

The onStop() method is called when the activity is no longer visible to the user, and resources that aren't needed anymore should be released. Additionally, any persistent state that the user is in the process of editing should be saved to prevent loss of work.

When and why would the onDestroy() method be called, and what should be done in this method?

The onDestroy() method is called when the activity is about to be destroyed, which can be caused by the activity finishing or being dismissed by the user, or a configuration change. Final cleanup of resources should be performed, but do not rely on this method to save user data - save it earlier instead.

How should UI state be saved and restored in response to lifecycle changes, and which method handles this?

To save and restore UI state in response to lifecycle changes, use the Bundle provided by the onSaveInstanceState() method. The onCreate() method receives the Bundle as an argument when the activity is created again.

What should be done in the onSaveInstanceState() method, and what is its purpose?

In the onSaveInstanceState() method, important UI state information should be stored in a Bundle that is used to recreate the activity if it is destroyed due to a configuration change or is terminated while in the background. This ensures that the user's work is retained and the UI state is consistent across changes.

Learn about the Activities life cycle, creating multiple Activities, using Intent Services, and displaying Toast messages in Android apps. Understand the essential role of the Activity class in building user interfaces and interacting with the user.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser