Lets go Flashcards

1
Q

What is the android stack?

A

The tech stack android uses by layer of abstraction:
1: System apps & User apps
2: Java API Frameworks
3: Native C/C++ Libraries & Android runtime
4: Hardware abstraction layer (HAL}
5: Linux kernel

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are contexts?

A

Context is an interface to global information about an application environment (it is an abstract class). It allows access to application-level resources and classes as well as up-calls for application-level operations like launching Activities, broadcasting, and receiving Intents. Passing contexts can lead to memory leaks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are event handlers in Android?

A

Event handlers are components that react to user interactions (like clicks, taps, and drags) or device events (like walking, driving, and tilting). They are “noticed” by the Android system and trigger appropriate responses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are resources in Android development?

A

Resources are external files and static content such as strings, layouts, colors, styles, API keys, and images that are used in an Android app. They are managed by the Android system and can be accessed via the Context object. Resources are stored in the /res dir of your project.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an Activity in Android?

A

An Activity represents a single screen with a user interface in Android. It is loosely coupled and can have a parent-child relationship with other activities. Activities are managed in a stack to handle navigation and lifecycle events.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an Intent in Android?

A

An Intent is a messaging object used to request an action from another app component via the Android system. It can be used to start activities, start services, and deliver broadcasts. There are implicit and explicit intents used for different purposes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the main callbacks in the Android activity lifecycle?

A
  1. onCreate(Bundle savedInstanceState)
  2. onStart()
  3. onRestart()
  4. onResume()
  5. onPause()
  6. onStop()
  7. onDestroy()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Fragment in Android?

A

A Fragment represents a portion of the UI in an activity and has its own lifecycle. It is reusable, can be shared across multiple activities, and allows for more modular and flexible UI designs. Fragments are managed using Fragment transactions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the methods of local data storage in Android?

A
  1. Local file storage (internal [private] and external [public])
  2. Shared Preferences (key-value store)
  3. SQLite databases (relational database)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does Android manage internet connections?

A

Android uses the ConnectivityManager to query the state of network connectivity and notify changes. NetworkInfo describes the status of a network interface. Permissions for internet access need to be declared in the Android manifest.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are threads managed in Android?

A

Threads in Android are managed using Java Threads, with the main thread handling UI updates and worker threads handling background tasks. The android.os.Handler package is used for asynchronous tasks, and operations lasting more than 5 seconds should be run asynchronously to avoid application not responding (ANR) dialogs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are broadcasts in Android?

A

Broadcasts are messages sent by the Android system or apps to notify about events of interest. They use Intent objects and can be system broadcasts or custom broadcasts. Broadcast receivers can be registered statically in the manifest or dynamically in code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How are notifications managed in Android?

A

Notifications in Android are grouped into channels, with importance levels and priorities set. They use PendingIntent to specify the action to be performed when the notification is tapped. Action buttons can be added using the addAction() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Cursor in Android’s SQLite database?

A

A Cursor is an interface that provides random read-write access to the result set returned by a database query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the role of the AndroidManifest.xml file in an Android application.

A

The AndroidManifest.xml file describes essential information about your app to the Android build tools, the Android operating system, and Google Play. This includes:
1. The app’s package name.
2. Components of the app such as activities, services, broadcast receivers, and content providers.
3. Permissions the app needs.
4. Minimum and target API levels.
5. Hardware and software features required.
6. Intent filters

This can be read by the PackageManager class without the need for opening your app! Important for implicit intents!?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Briefly describe the differences between Fragments and Activities in Android applications.

A

Activity: Represents a single screen with a user interface. It is an entry point for user interactions.
Fragment: Represents a portion of the UI within an activity. It is reusable, modular, and can be combined to create multi-pane UI. A fragment must always be hosted in an activity.

17
Q

What is the back stack? Briefly describe its functionality.

A

The back stack is a stack of activities managed by the Android system. When a new activity is started, it is pushed onto the stack. Pressing the back button pops the current activity off the stack and resumes the previous one. This provides a natural way for users to navigate back through the application’s activities.

18
Q

How does Android manage GUI reorientation when a device is moved from a portrait to a landscape view?

A

Android handles GUI reorientation by destroying and recreating the activity. This involves calling onPause(), onStop(), and onDestroy() for the old activity, followed by onCreate(), onStart(), and onResume() for the new configuration. Developers can override onConfigurationChanged() to handle changes manually without restarting the activity.

19
Q

The onCreate() method in an activity contains a parameter savedInstanceState. What class is savedInstanceState and what is it used for?

A

The savedInstanceState is a Bundle object that contains the activity’s previously saved state. It is used to restore the state of the activity if it is being recreated (e.g., after a rotation).

20
Q

Two ‘on-platform’ storage options on Android devices are SQLite and Shared Preferences. Explain the kind of use cases that you would use each for.

A

SQLite: Used for structured data storage, where complex querying and data manipulation are needed. Suitable for apps that require relational database capabilities.
Shared Preferences: Used for storing simple key-value pairs. Ideal for saving user settings and preferences.

21
Q

How do you internationalise an Android application?

A

Internationalisation in Android is done by:

Creating separate resource files for different locales (e.g., res/values-en, res/values-es).
Using string.xml files to define strings in different languages.
Accessing these resources using Context.getResources().getString(R.string.resource_name).

You can then get the current locale from the configurations and detect using system broadcasts when the user changes the locale.

22
Q

Differentiate between implicit and explicit intents with examples.

A

Explicit Intent: Specifies the exact component to start by name (e.g., Intent(context, TargetActivity.class)).

Implicit Intent: Specifies the action to perform and allows the system to find the appropriate component (e.g., Intent(Intent.ACTION_VIEW, Uri.parse(“http://www.example.com”))).

23
Q

Explain the concept of BroadcastReceiver in Android. Provide an example of its usage.

A

A BroadcastReceiver is a component that responds to broadcast messages from other applications or the system. They can be defined statically in the androidManifest or dynamically. Broadcasts can be received by multilple applications simultaneously or consecutively depending on whether it is a normal broadcast or ordered broadcast. Intent.setPackage() can be used to restrict which package names can receive your broadcast. You cannot receive system broadcasts statically (there are exceptions to this rule).

24
Q

To what extent would you describe Android applications as ‘loosely coupled’? Justify your opinion.

A

Activities: Each activity represents a single screen with its own lifecycle and operates independently. An activity can start another activity without needing to know its implementation details.

Services: Services run in the background to perform long-running operations. They are designed to operate independently from the activities and can be started or bound by other components without tight coupling.

Broadcast Receivers: These are components that respond to system-wide broadcast announcements. They operate independently and can react to broadcasts from the system or other applications.

Intents: Android uses Intents to facilitate communication between components. An Intent is a messaging object that can be used to request an action from another app component. This design allows for a high degree of flexibility and decoupling because the components do not need to know each other’s details to interact.

AndroidManifest.xml: This file declares the components of the application and their capabilities. It allows components to be loosely coupled by defining intent filters that specify which intents a component can handle. This mechanism allows components to be discovered and invoked dynamically at runtime.

25
Q

What is the function of a CursorAdapter? What does it produce from where and where would that product be used?

A

A CursorAdapter binds a Cursor to a ListView. It fetches data from a SQLite database and produces views for each row in the Cursor, which are then displayed in the ListView.

26
Q

Why should you not instantiate a long-running process from the main (GUI) thread? What approaches does Android provide to help you mitigate this issue?

A

Instantiating a long-running process from the main thread can cause the application to become unresponsive. Android provides several approaches such as AsyncTask, HandlerThread, IntentService, and JobScheduler to handle long-running tasks in background threads.

27
Q

What is a Looper? What is it used to do?

A

A Looper is a class used to run a message loop for a thread. It processes messages from a message queue and is commonly used in conjunction with Handler to perform tasks on a background thread.

28
Q

You decide to spawn a Java thread to handle an HTTP request to a remote server from one of your Activities. What Android API could you use to update your GUI when your thread’s run() method completes?

A

You can use a Handler to post a Runnable to the main thread’s message queue, which will update the GUI after the HTTP request completes.

29
Q

What are the differences between using an explicit Intent in your Android application to start an Activity generally and to start an Activity for a result? Briefly describe them.

A

Starting an Activity: Simply launches the specified activity.
Starting an Activity for a result: Uses startActivityForResult() and allows the calling activity to receive a result in onActivityResult().

30
Q

Describe the purpose and contents of the res folder in an Android project. Provide an explanation of the different types of resources it contains and the subdirectories they are contained in. Explain how these resources are accessed and utilized within application code.

A

The res folder contains app resources, by default:
drawable/: Images.
layout/: XML layouts.
values/: Strings, colors, dimensions.
raw/: Raw files.
Resources are accessed using resource IDs (e.g., R.drawable.image).

You can access these resources using the application’s context.

31
Q

What is the purpose of the setData() function in an Intent? What information can you pass with it?

A

The setData() function sets the data for the Intent. It can pass a URI that points to the data to be acted upon, such as a contact or a file.

32
Q

How are implicit intents processed by the Android system and sent to an appropriate Activity?

A

Implicit intents are processed by matching the intent’s action, data, and category with intent filters declared in AndroidManifest.xml. The system (Android PackageManager) then finds and launches the most appropriate activity to handle the intent.

33
Q

What is the purpose of setting a category in an Intent? How do you set an action in an Intent?

A

Categories provide additional information about the kind of component that should handle the intent. They are used to specify the environment in which the component should be used.

An action in an Intent specifies the operation to be performed. For example, viewing a webpage, dialing a phone number, or opening a specific type of file.

34
Q

What is an Intent Filter and how is it used in an Android application?

A

An Intent Filter is a component in an Android application that declares the types of intents that a component can respond to. It is defined in the AndroidManifest.xml file and specifies actions, categories, and data that the component can handle. This enables the system to find the appropriate component to start when an implicit intent is broadcast.

35
Q

What is the onActivityResult() method used for in Android? Provide an example of its usage.

A

The onActivityResult() method is used to handle the result returned by an activity that was started for a result. When an activity finishes and returns a result, this method is called in the calling activity to process the data.

36
Q

How can you secure broadcast intents in Android to prevent unauthorized apps from receiving them?

A

You can secure broadcast intents by setting a specific package for the intent or using permissions. This restricts the broadcast to only the intended receivers. Or by specifying a permission in the sendBroadcast() method.

Intent intent = new Intent(“com.example.CUSTOM_INTENT”);
intent.setPackage(“com.example.targetapp”);
sendBroadcast(intent);

or

sendBroadcast(intent, “com.example.permission.MY_PERMISSION”);

37
Q

What is a PendingIntent in Android, and how is it typically used?

A

A PendingIntent is a token that you give to another application, which grants it the right to perform an action with your application’s permissions. It is typically used in notifications and alarms to perform actions on behalf of your application.

38
Q

How can you handle configuration changes, like screen rotations, in Android without restarting the activity?

A

You can handle configuration changes by overriding onConfigurationChanged() in your activity and specifying the changes you want to handle in the AndroidManifest.xml.

39
Q

What is a Content Provider in Android, and what is it used for?

A

A Content Provider manages access to a structured set of data and provides a way to share data between different applications. It is used to encapsulate data and provide mechanisms for defining data security.