Mobile and Ubiquitous Computing Flashcards
What are the five layers in Android Platform Architecture from bottom to top?
Linux Kernel
Hardware abstraction layer
Native C/C++ libraries & Android Runtime
Java API framework
System apps
What does the linux kernel contain?
Hardware drivers, security, process and memory management,
File and Network I/O,
Power Management, Binder (Inter-Process Communication)
What does the hardware abstraction layer do?
Provides standard interfaces that expose device hardware capabilities to the Java API framework, bridging the gap between the linux kernel and hardware.
What are the native C/C++ Libraries?
Pre-compiled libraries optimized for performance and used for low-level system operations. Includes Webkit (Browser engine), Media Framework (Video/Audio), OpenGL (Graphics Engine), SQLite (Relational Database engine).
What is Android Runtime?
Android Runtime is an application runtime environment used by the Android OS. Contains core libraries such as Basic Java Classes, App Lifecycle, Internet/Web Services and Unit Testing. Java Code is converted to Java bytecode, which is converted to DEX bytecode, which is the input to ART.
What is the Java API Framework?
A collection of Java classes and interfaces that define the functionality available to Android applications.
What are five features of the the Java API Frameworks and what do they do?
View System - Builds an application’s UI.
Content Provider - Enables applications to access data from other applications.
Resource Manager - Provides access to non-code resources such as graphics.
Notification Manager - Enables all applications to display customer alerts in the status bar.
Activity Manager - Manages the lifecycle of apps and provides a common navigation backstack.
What is application part of the android platform architecture?
A set of core apps that come pre installed with android such as an email client, maps and a browser.
What is an activity?
An activity provides the window in which the app draws its UI. It is the entry point for an app’s interaction with the user. One activity implements one screen and most apps have several activities. Each activity must be registered in the manifest, and as a subclass of the base Activity class.
What is a service?
A service runs in the background and performs long running operations. It allows different processes to share data and request operations.
What are Broadcast Receivers?
Broadcast Receivers are a component of the android system that allow apps to listen and respond to an event. For example system broadcasts and customized broadcasts.
What are Content Providers?
A way for an app to access data and to share data with other apps. Provides an interface between an app and its data storage.
What is the android manifest?
The Android Manifest. is an XML file that serves as a blueprint for the Android application. It provides essential information about the app to the Android system, such as its package name, version, permissions, components, and configuration details.
What happens when an activity is launched?
It goes to onCreate()
What happens after onCreate()?
onStart()
What happens after onStart()?
onResume()
What happens after onResume()?
The activity runs
What happens on onPause()?
Either the App Process is killed, it resumes with onResume(), or it goes to onStop()
What happens on onStop()?
Either the App Process is killed, it restarts with onRestart(), or it it goes on to onDestroy()
What happens on onDestroy()?
The activity is shut down
How is an activity restarted after the App Process is killed?
onCreate()
What is onCreate()?
Called when activity is created. Initializes the activity and carries out the functions super.onCreate(), set content view, retain references to views, configure views.
What is onStart()?
Called when the activity is about to become visible. Typically starts up visible only behaviours and loads persistent app state.
What is onResume()?
Called when the activity is visible and about to start interacting, will usually start foreground only behaviors.
What is onRestart()?
Called when Activity is stopped but about to be started again, and needs to handle any special processing needed.
What is onPause()?
When you are about to switch to another activity. Shuts down foreground only behaviour and saves persistent app state.
What is onStop?
When the activity is no longer visible, it will usually cache activity state. May not be called if Android kills app.
What is onDestroy()?
When it is about to be destroyed and it releases activity resources. May not be called if android kills app.
How do you start a new activity from an initial activity?
Context context = FirstActivity.this;
Class destinationActivity = SecondActivity.class;
Intent intent = new Intent (context, destinationActivity);
startActivity(intent);
How can you send data from one activity to another using Intent data?
Add the data (URI) to the intent.
For example:
Uri webpage = Uri.parse(“http://www.exeter.ac.uk”);
intent.setData(webpage);
How can you send data from one activity to another using Intent Extras and putExtra()?
Determine the key for information, then use the putExtra() methods to add <key, value> pairs.
How can you send data from one activity to another using Intent Extras and bundles?
Create a bundle then use putString() to add the key and value to the bundle. Then use putExtra(bundle) on the intent.
How do you receive data from another activity sent with an intent with data?
getIntent() to retrieve the intent. Then intent.getData() to get the data from the intent
How do you receive data from another activity sent with an intent with an extra?
getIntent() to retrieve the intent. Then intent.get**Extra() to get extra data out of the intent. For example getStringExtra for a string.
How do you receive data from another activity sent with an intent with a bundle of extras?
getIntent() to retrieve the intent. Then intent.getExtra() to get bundle out of the intent. Then bundle.getString() if it is a string.
How do you launch an activity to get a response from it?
Firstly call startActivityForResult(Intent intent, int requestCode) to call the activity. Then add data to an intent in the second activity, and use setResult(int resultCode, Intent data) to set the result, and finish() to finish the activity. Finally on the first activity, Override the onActivityResult(int requestCode, int resultCode, Intent data) method, check if resultCode = RESULT_OK, then process the data.
What is explicit intent?
An Intent that explicitly specifies the target component (e.g., activity, service) to be invoked. Usually used to call other activities.
What is implicit intent?
An Intent that does not specify the target component (e.g., activity, service) explicitly but describes the action to be performed. Used for activating components that can handle a particular action, such as opening a web page, sending an email, or sharing content.
What is the use of intent field named action?
Specifies the generic action the receiving activity should perform.
What is the use of the intent field named category?
Specifies the category of component that should handle the intent.
What is the use of the intent field named type?
It indicates the MIME type of the intent data (e.g., image/png, image/jpeg,
text/html, text/plain). If you don’t specify a MIME type, Android will infer one.
What is the use of the intent field named flag?
It specifies how the intent should be handled
How do you create and resolve an implicit intent?
To create, create an an intent with an action string. Then set any fields such as extras or type. Then use resolve activity to make sure that the system packet manager has a match for the intent, and start the activity if it does.
How can you handle more than one app being able to handle an intent?
Create a selection or chooser dialogue, and start the activity through that.
How can an activity receive an implicit intent?
By putting intent filters in the android manifest, which then are compared with the intent fields to see if they are compatible. If they are it gets the intent, gets the data/extras, performs the task, and may return data.
What does the <action> intent filter mean?</action>
It describes which actions an activity can perform.
What does the <data> </data>intent filter mean?
It describes which data types that the activity can handle.
What is a view?
The view class is a basic building block and superclass for UI components. It occupies a rectangular space on screen and has a location and dimension. There are lots of predefined views such as TextView, ImageView, ScrollView and RecyclerView.
What is a viewgroup?
ViewGroups are special types of Views that act as containers for other Views. They organize and manage the layout of child Views within them.
What is a layout?
A layout is a type of viewgroup that dictates the arrangement and organization of UI elements within an Activity or Fragment. They can be declared in XML or instantiated at runtime.
What is a relative layout?
A RelativeLayout is a type of ViewGroup in Android that arranges its child Views relative to one another or to the parent container.
What is a constraint layout?
A ConstraintLayout is a type of ViewGroup that allows the creation of flexible and dynamic layouts using a system of constraints to define the position and alignment of UI elements relative to each other and to the parent container.
What is an AdapterView and how does it work?
An AdapterView in Android displays a list of data items. It works by connecting data to views using an adapter, and populating on runtime. It can also handle user selections with OnItemClickListener.
What is ListView?
A subclass of AdapterView that has vertical scroll, horizontal row entries, and pick item.
What is GridView?
A subclass of AdapterView that displays a list of scrollable items with specifies number of rows and columns
What is a linear layout?
A linear layout arranges its child Views in a single direction, either horizontally or vertically. This is often used when views need to be organized in a linear fashion.
What advantages does RecyclerView have over ListView?
- It supports vertical, horizontal, and grid layouts instead of only vertical.
- It has more efficient view recycling and memory management.
- It is more optimized for large and dynamic data sets, which improves performance.
- Allows for dynamic data changes with notifications for item insertion and removal.
- Built in support for custom decorations and animations.
Easier to create complex item views and layouts.
What is the principle behind RecyclerView?
Items off screen are kept in a queue for reuse. The list items are binded with new content that can be scrolled in. Items that are scrolled out are added back into the queue.
What are the four components of RecyclerView and what do thet do?
Layout Manager: Manages the arrangement of items within the RecyclerView.
RecyclerView: The scrolling list that contains the list items.
Adapter: Binds data to the RecyclerView. Contains the ViewHolder which contains the view information for displaying one list item.
Data: Local data, a database or remote data.
What is a ViewHolder?
It describes an item view and metadata about its place. The adapter adds data to view holders. The layout is defined in xml and can contain any kind of view. It minimizes the number of views kept around and the number of views to be created when scrolling by creating more views than screen capacity, and caching and reusing views with different data as they scroll in and out.
Why are ViewHolders used?
It doesn’t need to use findViewById(), as it is better to cache the views in a view holder. Therefore you can access those views later without having to repeatedly make findViewById() calls. When it scrolls the view holders will be reused and the adapter will bind new data to them.
How do you implement a recycler view?
FIrstly add RecyclerView to the gradle file. Create an XML layout file for the individual items in the list/grid. Define a ViewHolder class that extends RecyclerView.ViewHolder. Create an adapter class that extends RecyclerView.Adapter<ViewHolder>, and override onCreateViewHolder() to inflate item layouts, onBindViewHolder() to bind data to views, and getItemCount() to return the number of items in the dataset. In the main activity give the RecyclerView a LayoutManager, instantiate the adapter and set it on the RecyclerView using setAdapter().</ViewHolder>
How are fragments modular?
Composing an Activity from several fragments offers flexibility, you can re-use fragments, and they usually have a UI.
How does the fragments lifecycle connect to the activity?
A fragment has its own lifecycle and receives its own events but is also tied to its parent activity lifecycle.
What are the three fragment lifecycle states and what do they mean?
Resumed: Fragment is visible in the containing activity.
Paused: Another activity is in the foreground (the containing
activity is in the background).
Stopped: Fragment is not visible.
When is onAttach in the fragment lifecycle called, and what does it do?
Called when the fragment is attached to its host activity, preceded by instantiation of the Fragment and followed by onCreate(). This method establishes a connection to the parent activity.
When is onCreate in the fragment lifecycle called, and what does it do?
Invoked when the fragment is being created, preceded by onAttach() and followed by onCreateView(). Initialization tasks such as setting up variables and resources are performed here.
When is onCreateView in the fragment lifecycle called and what does it do?
Responsible for creating the fragment’s view hierarchy, preceded by onCreate() and followed by onViewCreated(). Inflate the layout XML or create views programmatically within this method
When is onViewCreated in the fragment lifecycle called and what does it do?
Called after onCreateView(), indicating that the view hierarchy has been created, preceded by onCreateView() and followed by onStart(). Initialize UI elements and bind data to views here.