Search This Blog

Sunday, 16 March 2025

Tutorial III & IV (MAD) Questions and Answers

0 comments

TUTORIAL III

(24-03-2025)



Question 1: 

Write notes on Intents.  Discuss briefly the two types of Intents available for application development in Android.

Answer:

Intents are a messaging system that allows Android components to request actions from other components.  They act as a facilitator, enabling communication between different parts of an Android application or even between different applications.

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. This information includes:

  • 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:
    • 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.
}


Question 2: Define Intent Filter.  And state the purpose of Intent Filter in developing an application in Android.

Question 3: What is Broadcast Receiver?  Also explain the role of Notifications in an Android application.

Question 4: Demonstrate with code snippet how data can be shared betwen Activities using Intents while running an Android application.

Question 5: Demonstrate the use of Broadcast Receiver in receiving and responding to the messages being broadcast in an android application.

TUTORIAL IV

(31-03-2025)

 
Question 1:  In detail explain J2ME Architecture with a neat diagram.
 
In mid-1999, J2ME was introduced to developers of intelligent wireless devices and small computing devices who need to incorporate cross-platform functionality in their products.
  • 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.
Expectations of Consumers of Mobile and Small Computing Devices include the following:
  • 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
J2ME architecture doesn’t replace the operating system of a small computing device. Instead, J2ME architecture consists of layers located above the native operating system, collectively referred to as the Connected Limited Device Configuration (CLDC).

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.
 
Question 2: Explain some of the J2ME Best Practices.
 
Question 3: Explain the anatomy of a MIDlet suite.
 
Question 4: Write a MIDlet for selecting an option from a Choice Group object.
 
Question 5: Define Profile in J2ME.  Name the profiles defined in J2ME for CLDC devices.

Leave a Reply