QB Mad
QB Mad
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.
<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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
</RelativeLayout>
· Java file
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
@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.
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.