0% found this document useful (0 votes)
12 views9 pages

QB Mad

The document discusses broadcast receivers, fragments, and developing an Android application using radio buttons and XML layout. It also covers activity and service lifecycles, progress bars, and content provider basics.

Uploaded by

laxmimane245
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

QB Mad

The document discusses broadcast receivers, fragments, and developing an Android application using radio buttons and XML layout. It also covers activity and service lifecycles, progress bars, and content provider basics.

Uploaded by

laxmimane245
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 9

I) Broadcast receiver: Broadcast in android is the system-wide events that can

occur when the device starts, when a message is received on the device or when
incoming calls are received, or when a device goes to airplane mode, etc.
Broadcast Receivers are used to respond to these system-wide events. Broadcast
Receivers allow us to register for the system and application events, and when
that event happens, then the register receivers get notified. There are mainly two
types of Broadcast Receivers:
 Static Broadcast Receivers: These types of Receivers are declared in
the manifest file and works even if the app is closed.
 Dynamic Broadcast Receivers: These types of receivers work only if
the app is active or minimized.

ii) Fragment: A fragment represents a modular portion of the user interface within
an activity. A fragment has its own lifecycle, receives its own input events, and you
can add or remove fragments while the containing activity is running.

1. Elaborate Android Security Model.


2. Develop an android application using radio button.

3. <?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1"
android:onClick="onRadioButtonClicked" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2"
android:onClick="onRadioButtonClicked" />

<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
</LinearLayout>

package com.example.radiobutton;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void onRadioButtonClicked(View view) {


boolean isChecked = ((RadioButton) view).isChecked();

// Display a toast message when a radio button is clicked


if (isChecked) {
Toast.makeText(this, "You have selected " + ((RadioButton)
view).getText(), Toast.LENGTH_SHORT).show();
}
}
}

4. Draw and explain activity life cycle.


5. Circular progress bar

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/rectangularProgressBar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_centerInParent="true"
style="@Style/Widget.ProgressBar.Horizontal" />

</RelativeLayout>
· Java file
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ProgressBar progressBar =
findViewById(R.id.rectangularProgressBar);
progressBar.setProgress(50); // Set progress from 0 to 100
}

}
6. Service life cycle
To create an service, you create a Java class that extends the Service base class or
one of its existing subclasses. The Service base class defines various callback
methods and the most important are given below. You don't need to implement all
the callbacks methods. However, it's important that you understand each one and
implement those that ensure your app behaves the way users expect.

onStartCommand()
The system calls this method when another component, such as an activity, requests that the
service be started, by calling startService(). If you implement this method, it is your responsibility
to stop the service when its work is done, by calling stopSelf() or stopService() methods.
onBind()
The system calls this method when another component wants to bind with the service by
calling bindService(). If you implement this method, you must provide an interface that clients
use to communicate with the service, by returning an IBinder object. You must always
implement this method, but if you don't want to allow binding, then you should return null.

onUnbind()
The system calls this method when all clients have disconnected from a particular interface
published by the service.

onRebind()
The system calls this method when new clients have connected to the service, after it had
previously been notified that all had disconnected in its onUnbind(Intent).

onCreate()
The system calls this method when the service is first created
using onStartCommand() or onBind(). This call is required to perform one-time set-up.

onDestroy()
The system calls this method when the service is no longer used and is being destroyed. Your
service should implement this to clean up any resources such as threads, registered listeners,
receivers, etc.

Content provider basics


bookmark_border

A content provider manages access to a central repository of data. A provider is


part of an Android application, which often provides its own UI for working with
the data. However, content providers are primarily used by other applications,
which access the provider using a provider client object. Together, providers and
provider clients offer a consistent, standard interface to data that also handles
interprocess communication and secure data access.

Typically you work with content providers in one of two scenarios: implementing
code to access an existing content provider in another application or creating a
new content provider in your application to share data with other applications.
A fragment represents a modular portion of the user interface within an activity. A
fragment has its own lifecycle, receives its own input events, and you can add or
remove fragments while the containing activity is running.

This document describes how to create a fragment and include it in an activity.

You might also like