0% found this document useful (0 votes)
22 views22 pages

UNIT-1.docx-1

Mobile application development involves creating software for Android and iOS platforms using various approaches such as native, cross-platform, web-based, and hybrid apps. Key trends include AI integration, IoT, 5G technology, and low-code development, while challenges include device fragmentation and security. The Android operating system, built on a Linux kernel, features a layered architecture and supports a range of development tools and environments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views22 pages

UNIT-1.docx-1

Mobile application development involves creating software for Android and iOS platforms using various approaches such as native, cross-platform, web-based, and hybrid apps. Key trends include AI integration, IoT, 5G technology, and low-code development, while challenges include device fragmentation and security. The Android operating system, built on a Linux kernel, features a layered architecture and supports a range of development tools and environments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

UNIT – I ANDROID FUNDAMENTALS

Mobile Application Development

Definition

Mobile application development refers to the process of creating software applications that
run on mobile devices.

Designed for two main platforms

●​ Android (developed by Google)


●​ iOS (developed by Apple)

Development Approaches

1.​ Native Development


1.​ Native App Development: Involves creating separate apps for each platform
(iOS, Android) using platform-specific languages and tools.
▪​ iOS: Swift, Objective-C
▪​ Android: Kotlin, Java
2.​ Offers high performance and access to device features.

2.​ Cross-Platform Development


1.​ Cross-platform development is a method for creating software applications
that work with multiple mobile operating systems or platforms.
2.​ Write code once, deploy on multiple platforms.
3.​ Common frameworks:
▪​ Flutter (Dart)
▪​ React Native (JavaScript)
▪​ Xamarin (C#)

Prepared by M. AZHAGESAN AP/CSE-KSRCE


3.​ Web-Based Apps
1.​ Responsive websites optimized for mobile use.
2.​ Built using HTML5, CSS, and JavaScript.

4.​ Hybrid Apps


1.​ Combines web and native components.
2.​ Examples: Ionic, Apache Cordova.

Development Tools

1.​ Integrated Development Environments (IDEs):


1.​ Android Studio (for Android)
2.​ Xcode (for iOS)

Prepared by M. AZHAGESAN AP/CSE-KSRCE


2.​ Version Control: Git, GitHub
3.​ Testing Tools: Appium, Firebase Test Lab
4.​ Backend Services: Firebase, AWS Amplify, Microsoft Azure

Trends in Mobile App Development

1. Artificial Intelligence (AI) and Machine Learning (ML) Integration

●​ Personalized user experiences (e.g., chatbots, voice assistants).


●​ AI-driven analytics and predictions.
●​ Tools: TensorFlow Lite, Core ML.

2. Internet of Things (IoT)

●​ Integration with smart devices and wearables.


●​ Examples: Smart home apps, fitness trackers.

3. 5G Technology

●​ Faster speeds and improved connectivity.


●​ Enhanced AR/VR applications and real-time streaming.

4. Augmented Reality (AR) and Virtual Reality (VR)

●​ Immersive experiences in gaming, education, and e-commerce.


●​ Examples: IKEA Place (AR), Pokémon GO (AR).

5. Progressive Web Apps (PWAs)

●​ Apps that behave like native apps but are accessed via a browser.
●​ Example: Twitter Lite.

6. Blockchain Technology

●​ Secure mobile transactions and decentralized apps (dApps).


●​ Used in industries like finance and supply chain.

7. Mobile Commerce (mCommerce)

●​ Increasing use of mobile apps for shopping and payments.


●​ Integration with digital wallets like Google Pay, Apple Pay.

8. On-Demand Apps

●​ Apps providing services like food delivery, transportation, and home services.
●​ Examples: Uber, DoorDash.

9. Low-Code/No-Code Development

●​ Platforms enabling faster app development with minimal coding.


●​ Examples: OutSystems, Appgyver.

10. Cloud Computing Integration

Prepared by M. AZHAGESAN AP/CSE-KSRCE


●​ Apps leveraging cloud infrastructure for storage and computing.
●​ Examples: Dropbox, Google Drive.

Challenges in Mobile App Development

1.​ Device Fragmentation: Ensuring compatibility across devices and screen sizes.
2.​ Performance Optimization: Balancing performance and battery consumption.
3.​ Security: Protecting user data and preventing breaches.
4.​ User Retention: Creating engaging and user-friendly designs.

Android Overview and Versions

Overview of Android

1.​ Definition: Android is an open-source mobile operating system developed by Google,


primarily for touchscreen devices like smartphones and tablets.
2.​ Foundation: Built on a modified Linux kernel.
3.​ Programming Language: Java, Kotlin, and C++ are commonly used.
4.​ Features:
1.​ Multitasking
2.​ Customizable user interface
3.​ Integration with Google services
4.​ Wide variety of applications via Google Play Store

Key Components of Android

1.​ Applications: User-facing apps like Gmail, Maps, etc.


2.​ Application Framework: Manages app components like activities, content
providers, etc.
3.​ Libraries: Pre-installed code for specific functions, e.g., SQLite for database
management.
4.​ Android Runtime (ART): Optimizes app performance and memory usage.
5.​ Linux Kernel: Manages hardware interaction and system resources.

Android Version History


Version Code Name Release Date Key Features

1.0 - September 2008 First Android release with basic features.

1.5 Cupcake April 2009 Virtual keyboard, widgets support.

1.6 Donut September 2009 Better screen resolution support.

2.2 Froyo May 2010 Mobile hotspot, push notifications.

4.0 Ice Cream Sandwich October 2011 Unified UI for smartphones and tablets.

4.4 KitKat October 2013 Improved performance, "OK Google" voice search.

5.0 Lollipop November 2014 Material design, battery saver.

6.0 Marshmallow October 2015 App permissions, fingerprint support.

Prepared by M. AZHAGESAN AP/CSE-KSRCE


7.0 Nougat August 2016 Split-screen multitasking, improved Doze mode.

8.0 Oreo August 2017 Picture-in-picture, notification dots.

9.0 Pie August 2018 Adaptive battery, gesture navigation.

10 - September 2019 Dark mode, improved privacy controls.

11 - September 2020 Chat bubbles, screen recorder.

12 - October 2021 Material You design, privacy dashboard.

13 - August 2022 Themed app icons, enhanced security features.

14 - October 2023 Satellite connectivity, enhanced foldable support.


Importance of Android Updates

1.​ Security: Patches for vulnerabilities.


2.​ New Features: Enhanced functionality and design.
3.​ Performance: Improved speed and battery life.
4.​ Compatibility: Support for new hardware and APIs

Android Open Stack Overview

Android Open Stack represents the layered architecture of the Android operating
system. It ensures the smooth functioning of applications and system services by
organizing components into distinct layers.

Prepared by M. AZHAGESAN AP/CSE-KSRCE


Layers of Android Open Stack
1.1​ Linux Kernel
Linux kernel development is the term used to describe the process of building and
maintaining the core of Linux.

1.​ Foundation of the Stack: Provides core system services.


2.​ Key Functions:
1.​ Hardware Abstraction (Drivers for display, camera, Wi-Fi, etc.)
2.​ Power Management
3.​ Process Management
4.​ File System Management
5.​ Network Stack

1.2​Hardware Abstraction Layer (HAL)


It is a software component that acts as an interface between a computer's
hardware and its operating system (OS).

●​ Role: Interfaces between the Linux Kernel and higher-level APIs.


●​ Components:
o​ Specific libraries for hardware features like audio, Bluetooth, sensors.

1.3​Android Runtime (ART)

Prepared by M. AZHAGESAN AP/CSE-KSRCE


Android runtime (ART) is the managed runtime used by apps and some
system services on Android

●​ Key Features:
o​ Runs apps in Dalvik Virtual Machine (for older versions) or ART (for newer
versions).
o​ Provides Just-In-Time (JIT) and Ahead-Of-Time (AOT) compilation for
optimized app performance.
●​ Core Libraries: Support for Java-based development.

1.4​Native Libraries
Native libraries are platform-specific library files, including. dll, . so, or
*SRVPGM objects, that can be configured within shared libraries.

1.​ Purpose: Provide core functionalities for Android.


2.​ Examples:
1.​ SQLite: Database management.
2.​ OpenGL ES: Graphics rendering.
3.​ WebKit: Browser engine.
4.​ SSL/HTTPS: Secure communication.

1.5​Application Framework
It is a software framework used by software developers to implement the
standard structure of application software.

●​ Role: Provides APIs for developers to build applications.


●​ Components:
o​ Activity Manager: Manages app lifecycle.
o​ Content Providers: Enables app data sharing.
o​ Resource Manager: Manages external resources like strings, layouts.
o​ Notification Manager: Controls and displays system notifications.
o​ Location Manager: Provides location-based services.

1.6 Applications

●​ Topmost Layer: User-facing apps like:


o​ Pre-installed apps (Phone, Messages, Settings)
o​ User-installed apps (Social Media, Games, etc.)
●​ Apps use the Application Framework to interact with lower layers.

Features of the Android Open Stack

Features include a user-friendly interface, overall support, a broad range of software


offerings, and mass production for Android devices’

●​ Open Source: Fully customizable and modifiable under the Android Open Source
Project (AOSP).
●​ Modularity: Flexible design supports various devices and hardware configurations.

Prepared by M. AZHAGESAN AP/CSE-KSRCE


●​ Extensibility: Allows developers to build and integrate new functionalities.
●​ Security: Sandbox environment for apps, ensuring safe user data handling.
●​ Cross-Platform Compatibility: Works on smartphones, tablets, TVs, and wearable
devices.
●​ Manipulation of the File System.
●​ Handling I/O Operations.
●​ Error Handling.
●​ Resource Allocation.

Setting up Android Development & Simple Android Application


Development –

Java Development Kit (JDK)

1.​ Download Android Studio:


o​ Visit the Android Studio official site.
2.​ Install Android Studio:
o​ Follow the installation wizard for your operating system (Windows, macOS,
Linux).

b. Configure Android Studio

1.​ SDK Manager:


o​ Open Android Studio.
o​ Navigate to Tools > SDK Manager.
o​ Install the latest Android SDK versions, build tools, and system images.
2.​ AVD Manager (Optional):
o​ Set up a virtual device via Tools > AVD Manager if you want to test your app
on an emulator.

Eclipse IDE with ADT Plugin

Prepared by M. AZHAGESAN AP/CSE-KSRCE


Android SDK

Android Virtual Device (AVD) for testing

•​ Step 1: Setup Java Development Kit (JDK)


•​ Step 2: Configure Android SDK

2. Create a New Android Project

1.​ Open Eclipse and navigate to:​


File > New > Android Application Project
2.​ Enter the project details:
o​ Application Name: MyFirstApp
o​ Project Name: MyFirstApp

Prepared by M. AZHAGESAN AP/CSE-KSRCE


o​ Package Name: com.example.myfirstapp
o​ Minimum Required SDK: Select an appropriate version
o​ Target SDK & Compile With: Choose the latest version
o​ Theme: Choose "Holo Light" or any other theme
3.​ Click Next and configure the project settings.

Modify the Layout

1.​ Open res/layout/activity_main.xml.


2.​ Update the XML to design a simple layout

s<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Android!"
android:textSize="24sp"
android:layout_marginBottom="20dp"/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>

Prepared by M. AZHAGESAN AP/CSE-KSRCE


Configure the Project Structure
src/ → Contains Java source files (e.g., MainActivity.java)
res/ → Resource files like layouts (XML), images, and values
AndroidManifest.xml → The app’s configuration file
4. Edit the Main Activity
1.​ Open src/com.example.myfirstapp/MainActivity.java
2.​ Modify the code:

package com.example.myfirstapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity


{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Create a TextView dynamically
TextView textView = new TextView(this);
textView.setText("Hello, Android!");
// Set the content view to the textView
setContentView(textView);
}
}
Run the Application

1.​ Connect a physical Android device (enable USB Debugging) or launch an AVD.
2.​ Click Run (Run > Run As > Android Application).
3.​ The emulator/device should display "Hello, Android!".

Prepared by M. AZHAGESAN AP/CSE-KSRCE


Anatomy of an Android Application

Android App Components


An Android application is built using four main components:
a) Activities (User Interface)

●​ An Activity represents a single screen with a user interface.


●​ The main activity is the entry point of the application.

public class MainActivity extends AppCompatActivity {


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

Services (Background Processing)

●​ A Service runs in the background without a user interface.


●​ Used for tasks like music playback, data sync, or fetching data from the internet.

public class MyService extends Service {


@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Background task code
return START_STICKY;
}
}
Broadcast Receivers (Listening for Events)
●​ A Broadcast Receiver listens for system-wide events like battery low, network changes, or
incoming calls.
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcast Received!", Toast.LENGTH_SHORT).show();
}
}
Content Providers (Data Management)

●​ A Content Provider manages shared data between applications.


●​ Used to access contacts, media, or other databases.

2. Android App Structure


Project Directory Structure

Prepared by M. AZHAGESAN AP/CSE-KSRCE


MyApplication/

├── app/

│ ├── src/

│ │ ├── main/

│ │ │ ├── java/com/example/myapplication/ (Java source files)

│ │ │ ├── res/ (Resources like images, layouts, etc.)

│ │ │ ├── AndroidManifest.xml (App configuration)

├── build.gradle (Build script)

├── settings.gradle

3. Important Files in an Android App


a) AndroidManifest.xml (Configuration File)
●​ Declares essential app components.
●​ Defines app permissions and activities.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">

<application
android:allowBackup="true"
android:label="My App">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Java/Kotlin Files (App Logic)

●​ Contains business logic for the app.


●​ Located inside src/main/java/ in package folders.

res/ (Resources Folder)


Contains various resources like layouts, images, and values:

●​ res/layout/ → XML files for UI design (e.g., activity_main.xml)


●​ res/drawable/ → Images and graphical resources
●​ res/values/ → Strings, colors, and themes (strings.xml, colors.xml)
●​ res/mipmap/ → Icons for different screen sizes

Prepared by M. AZHAGESAN AP/CSE-KSRCE


<resources>
<string name="app_name">My Application</string>
</resources>

Gradle Build Scripts (Build & Dependencies)

dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'

4. App Lifecycle and Execution


a) Activity Lifecycle
Each activity has a lifecycle controlled by the system
@Override
protected void onPause() {
super.onPause();
Log.d("Lifecycle", "App is paused");
}

Running the Application

1.​ Open Android Studio (or Eclipse with ADT).


2.​ Click Run > Run 'app'.
3.​ Select a physical device (USB Debugging enabled) or Android Emulator (AVD).

Activity and Life Cycle


The activity lifecycle is the set of states an activity can be in during its entire lifetime, from the time
it's created to when it's destroyed and the system reclaims its resources.

Android Activity Lifecycle is controlled by 7 methods of android.app.Activity class. The android


Activity is the subclass of ContextThemeWrapper class.

Method Descriptiontion

Prepared by M. AZHAGESAN AP/CSE-KSRCE


onCreate called when activity is first created.

onStart called when activity is becoming visible to the user.

onResume called when activity will start interacting with the user.

onPause called when activity is not visible to the user.

onStop called when activity is no longer visible to the user.

onRestart called after your activity is stopped, prior to start.

onDestroy called before the activity is destroyed.

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


<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.and
roid.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.activitylifecycle.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

package example.javatpoint.com.activitylifecycle;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Prepared by M. AZHAGESAN AP/CSE-KSRCE


setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate invoked");
}
@Override
protected void onStart() {
super.onStart();
Log.d("lifecycle","onStart invoked");
}
@Override
protected void onResume() {
super.onResume();
Log.d("lifecycle","onResume invoked");
}
@Override
protected void onPause() {
super.onPause();
Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
Log.d("lifecycle","onStop invoked");
}
@Override
super.onRestart();
Log.d("lifecycle","onRestart invoked");
}
@Override
protected void onDestroy() {
Log.d("lifecycle","onDestroy invoked");
}
OUT PUT

Prepared by M. AZHAGESAN AP/CSE-KSRCE


Intents.
Android Intent is the message that is passed between components such as
activities, content providers, broadcast receivers, services etc. he dictionary meaning of
intent is intention
Android intents are mainly used to:

1.​ Start the service


2.​ Launch an activity
3.​ Display a web page
4.​ Display a list of contacts
5.​ Broadcast a message
6.​ Dial a phone call etc.

​ Types of Android Intents

Prepared by M. AZHAGESAN AP/CSE-KSRCE


1) Implicit Intent
Implicit Intent doesn't specifiy the component. In such case, intent provides information of
available components provided by the system that is to be invoked.

Intent intent=new Intent(Intent.ACTION_VIEW);


intent.setData(Uri.parse("http://www.javatpoint.com"));
startActivity(intent);
2) Explicit Intent
Explicit Intent specifies the component. In such case, intent provides the external class to be
invoked.

Intent i = new Intent(getApplicationContext(), ActivityTwo.class); startActivity(i);


Activity_main.xml
File: activity_main.xml
1.​ <?xml version="1.0" encoding="utf-8"?>
2.​ <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/ap
k/res/android"
3.​ xmlns:app="http://schemas.android.com/apk/res-auto"
4.​ xmlns:tools="http://schemas.android.com/tools"
5.​ android:layout_width="match_parent"
6.​ android:layout_height="match_parent"
7.​ tools:context="example.javatpoint.com.implicitintent.MainActivity">
8.​
9.​ <EditText
10.​ android:id="@+id/editText"
11.​ android:layout_width="wrap_content"
12.​ android:layout_height="wrap_content"
13.​ android:layout_marginEnd="8dp"
14.​ android:layout_marginStart="8dp"
15.​ android:layout_marginTop="60dp"
16.​ android:ems="10"
17.​ app:layout_constraintEnd_toEndOf="parent"
18.​ app:layout_constraintHorizontal_bias="0.575"
19.​ app:layout_constraintStart_toStartOf="parent"
20.​ app:layout_constraintTop_toTopOf="parent" />
21.​
22.​ <Button
23.​ android:id="@+id/button"
24.​ android:layout_width="wrap_content"
25.​ android:layout_height="wrap_content"
26.​ android:layout_marginRight="8dp"
27.​ android:layout_marginLeft="156dp"
28.​ android:layout_marginTop="172dp"
29.​ android:text="Visit"
30.​ app:layout_constraintEnd_toEndOf="parent"
31.​ app:layout_constraintHorizontal_bias="0.0"
32.​ app:layout_constraintStart_toStartOf="parent"
33.​ app:layout_constraintTop_toBottomOf="@+id/editText" />
34.​</android.support.constraint.ConstraintLayout>

Activity class
File: MainActivity.java
Prepared by M. AZHAGESAN AP/CSE-KSRCE
1.​ package example.javatpoint.com.implicitintent;
2.​
3.​ import android.content.Intent;
4.​ import android.net.Uri;
5.​ import android.support.v7.app.AppCompatActivity;
6.​ import android.os.Bundle;
7.​ import android.view.View;
8.​ import android.widget.Button;
9.​ import android.widget.EditText;
10.​
11.​public class MainActivity extends AppCompatActivity {
12.​
13.​ Button button;
14.​ EditText editText;
15.​
16.​ @Override
17.​ protected void onCreate(Bundle savedInstanceState) {
18.​ super.onCreate(savedInstanceState);
19.​ setContentView(R.layout.activity_main);
20.​
21.​ button = findViewById(R.id.button);
22.​ editText = findViewById(R.id.editText);
23.​
24.​ button.setOnClickListener(new View.OnClickListener() {
25.​ @Override
26.​ public void onClick(View view) {
27.​ String url=editText.getText().toString();
28.​ Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
29.​ startActivity(intent);
30.​ }
31.​ });
32.​ }
33.​}

OUTPUT

Prepared by M. AZHAGESAN AP/CSE-KSRCE


​ ​

ANDROID Services and Content Providers

Service is a component that allows an application to perform background operations without


a visible user interface.

Types of Services

●​ Foreground Service: Runs in the foreground and requires user attention. For
example, a music player.
●​ Background Service: Runs in the background and performs tasks that the user may
not directly interact with. For example, syncing data.
●​ Bound Service: Allows components (like activities) to bind and interact with the
service.

Services in Android are a special component that facilitates an application to run in the
background in order to perform long-running operation tasks. The prime aim of a service is to
ensure that the application remains active in the background so that the user can operate
multiple applications at the same time
Content Provider is a mechanism that enables applications to share data with each other by
providing a standardized way to access and manipulate data stored in a central repository,
often using a database like SQLite.

Prepared by M. AZHAGESAN AP/CSE-KSRCE


​ The role of the content provider in the android system is like a central repository in
which data of the applications are stored, and it facilitates other applications to securely
access and modifies that data based on the user requirements.
Android system allows the content provider to store the application data in several ways.
Users can manage to store the application data like images, audio, videos, and personal
contact information by storing them in SQLite Database , in files , or even on a network .
Operations in Content Provider
Four fundamental operations are possible in Content Provider namely Create , Read , Update
, and Delete .
Create: Operation to create data in a content provider.
Read: Used to fetch data from a content provider.
Update: To modify existing data.
Delete: To remove existing data from the storage.
Working of the Content Provider
Components of android applications like Activity and Fragments use an object CursorLoader
to send query requests to ContentResolver. The ContentResolver object sends requests (like
create, read, update, and delete) to the ContentProvider as a client. After receiving a request,
ContentProvider process it and returns the desired result.

​ Creating a Content Provider:


Step 1: Create a new project
1.​ Click on File, then New => New Project.
2.​ Select language as Java/Kotlin.
3.​ Choose empty activity as a template
4.​ Select the minimum SDK as per your need.
Step 2: Modify the strings.xml file

Prepared by M. AZHAGESAN AP/CSE-KSRCE


<resources>
<string name="app_name">Content_Provider_In_Android</string>
<string name="hintText">Enter User Name</string>
<string name="heading">Content Provider In Android</string>
<string name="insertButtontext">Insert Data</string>
<string name="loadButtonText">Load Data</string>
</resources>
Step 3: Creating the Content Provider class
1.​ Click on File, then New => Other => ContentProvider.
2.​ Name the ContentProvider
3.​ Define authority (it can be anything for example “com.demo.user.provider” )
4.​ Select Exported and Enabled option
5.​ Choose the language as Java/Kotlin

Implementation

1.​ Extend the ContentProvider class.


2.​ Override methods like onCreate(), query(), insert(), etc.
3.​ Define the provider in AndroidManifest.xml.

public class MyContentProvider extends ContentProvider {


@Override
public boolean onCreate() {
// Initialize data source
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
// Query data
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
// Insert data
return null;
}
}

Prepared by M. AZHAGESAN AP/CSE-KSRCE

You might also like