TUTORIAL III
(24-03-2025)
Intents are a messaging system that allows Android components to request actions from other components.
Intents are used to start activities, services, and broadcast receivers. They facilitate inter-component communication and provide a way to trigger actions within the Android system.
An Intent object contains information that the system uses to determine which component should handle the request.
- Action: A string that specifies the action to be performed (e.g.,
ACTION_VIEW
,ACTION_SEND
). - Data: A URI that specifies the data to be acted upon (e.g., a URL, a file path).
- Category: Additional information about the action, used to filter components that can handle the Intent.
- Extras: Key-value pairs that carry additional data.
- Component Name: The explicit name of the component to be started.
- Flags: Instructions for how the Intent should be handled.
Types of Intents:
There are two main types of Intents: Explicit Intents and Implicit Intents
Explicit Intents:
- Explicit Intents specify the exact component that should handle the Intent.
- They are used when you know the specific class name of the target component.
- This is typically used within your own application to start specific activities or services.
- Here is the sample code:
Intent intent = new Intent(this, TargetActivity.class);startActivity(intent);
- In the above java code, the component to be started is exactly specified by
TargetActivity.class
.
- Implicit Intents do not specify the exact component to handle the Intent.
- Instead, they declare a general action to be performed, and the Android system determines which component can handle it.
- This allows your application to interact with other applications on the device.
- The system matches the Intent's action, data, and category against the Intent filters declared by other applications in their manifest files
- Here is the sample code:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));startActivity(intent);
- In the example above, the android system will look for any application that can handle the
ACTION_VIEW
action, and data of type uri. If there are multiple applications that can handle this intent, the user will be presented with a chooser dialog. - It is crucial to verify that there is an application to handle implicit intents, before calling startActivity, to avoid app crashes as given below:
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);} else {// Handle the case where no activity can handle the intent.}
TUTORIAL IV
(31-03-2025)
- J2ME technology provides tools to build an industrial-strength Java application designed to run on a small computing device.
- J2ME application makes use the same basic programming constructs as used in a J2SE application. But, some routines commonly used in a J2SE application must be modified or excluded from a J2ME application.
- Quick response time
- Compatibility with companion services
- Full-featured applications
- Software and capabilities found on their desktop and laptop computers to be available on their cell phones and Personal Digital Assistant
The CLDC, which is installed on top of the Operating System, forms the run-time environment for small computing devices.
The J2ME architecture comprises three software layers (Figure 3-1):
- The first layer is the configuration layer that includes the Java Virtual Machine (JVM), which directly interacts with the native operating system. The configuration layer also handles interactions between the profile and the JVM.
- The second layer is the profile layer, which consists of the minimum set of application programming interfaces (APIs) for the small computing device.
- The third layer is the Mobile Information Device Profile (MIDP). The MIDP layer contains Java APIs for user network connections, persistence storage, and the user interface. It also has access to CLDC libraries and MIDP libraries.
A small computing device has two components supplied by the original equipment manufacturer (OEM). These are classes and applications.
- OEM classes are used by the MIDP to access device-specific features such as sending and receiving messages and accessing device-specific persistent data.
- OEM applications are programs provided by the OEM, such as an address book. OEM applications can be accessed by the MIDP.