Android Activities Overview
30 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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?

<p>when activity is becoming visible to the user</p> Signup and view all the answers

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

<p>onPause</p> Signup and view all the answers

What is the method called before the activity is destroyed?

<p>onDestroy</p> Signup and view all the answers

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

<p>To launch a new activity or get an existing activity to perform an action</p> Signup and view all the answers

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

<p>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</p> Signup and view all the answers

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

<p>To deliver a message to broadcast receivers</p> Signup and view all the answers

In Android, what is the purpose of Services?

<p>To facilitate an application to run in the background to perform long-running operation tasks</p> Signup and view all the answers

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

<p>Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(&quot;<a href="https://www.geeksforgeeks.org/">https://www.geeksforgeeks.org/</a>&quot;)); startActivity(intent);</p> Signup and view all the answers

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

<p>Intent i = new Intent(getApplicationContext(), ActivityTwo.class); startActivity(i);</p> Signup and view all the answers

What is the main objective of an Android service?

<p>To ensure that the application remains active in the background so that the user can operate multiple applications at the same time.</p> Signup and view all the answers

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

<p>Foreground Services</p> Signup and view all the answers

How can the execution of a Started Service be stopped?

<p>By calling stopService() method or the service can stop itself by using stopSelf() method.</p> Signup and view all the answers

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

<p>An application component binds itself with a service by calling bindService() method.</p> Signup and view all the answers

How can the execution of a Bounded Service be stopped?

<p>All the components must unbind themselves from the service by using unbindService() method.</p> Signup and view all the answers

What type of service does not require any user intervention?

<p>Background Services</p> Signup and view all the answers

What is the primary purpose of using Bundle in Android?

<p>Passing data from one activity to another</p> Signup and view all the answers

What type of data can be stored in a Bundle?

<p>All types of values (int, String, boolean, char)</p> Signup and view all the answers

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

<p>Using getIntent().getExtras() and getString(key, default_value)</p> Signup and view all the answers

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

<p>Viewing details of a single item, creating a new item, showing settings, and accessing services in other apps</p> Signup and view all the answers

What is the purpose of an Intent in Android?

<p>A messaging object that passes between components</p> Signup and view all the answers

How is a Bundle passed to an Intent?

<p>Using Intent.putExtras(Bundle)</p> Signup and view all the answers

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

<p>You should perform app startup logic and inflate the UI in the onCreate() method.</p> Signup and view all the answers

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

<p>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.</p> Signup and view all the answers

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

<p>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.</p> Signup and view all the answers

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

<p>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.</p> Signup and view all the answers

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

<p>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.</p> Signup and view all the answers

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

<p>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.</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser