SlideShare a Scribd company logo
1 of 55
Data Transfer between
Activities & Databases
Lecturer Faiz Ur Rehman
University of Mianwali
Intent
• Android uses Intent for communicating between the components of
an Application and also from one application to another application.
• Intent are the objects which is used in android for passing the
information among Activities in an Application and from one app to
another also. Intent are used for communicating between the
Application components and it also provides the connectivity
between two apps
Example
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
getApplicationContext() returns the context for your foreground activity.
Android intents are mainly used to:
•Start the service
•Launch an activity
•Display a web page
•Display a list of contacts
•Broadcast a message
•Dial a phone call etc.
Types of Intent
Explicit Intent:
• Explicit Intents are used to connect the application internally.
• Explicit Intent work internally within an application to perform
navigation and data transfer.
• Example
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);
Implicit Intent:
• In Implicit Intents we do need to specify the name of the component.
• We just specify the Action which has to be performed and further this
action is handled by the component of another application.
• The basic example of implicit Intent is to open any web page
• Example
Intent intentObj = new Intent(Intent.ACTION_VIEW);
intentObj.setData(Uri.parse("https://www.abhiandroid.com"));
startActivity(intentObj);
Intent Uses in android:
1. Intent for an Activity:
• Every screen in Android application represents an activity. To start a
new activity you need to pass an Intent object to startActivity()
method. This Intent object helps to start a new activity and passing
data to the second activity.
2. Intent for Services:
• Services work in background of an Android application and it does not
require any user Interface. Intents could be used to start a Service
that performs one-time task
• (for example: Downloading some file)
3. Intent for Broadcast Receivers:
• There are various message that an app receives, these messages are
called as Broadcast Receivers. (For example, a broadcast message
could be initiated to intimate that the file downloading is completed
and ready to use). Android system initiates some broadcast message
on several events, such as System Reboot, Low Battery warning
message etc.
4. Display a list of contacts
5. Dial a phone call etc.
Intent Filter:
• decide the behavior of an intent.
• -Intent about the navigation of one activity to another, that can be
achieve by declaring intent filter.
• -We can declare an Intent Filter for an Activity in manifest file.
• - Intent filters specify the type of intents that an Activity, service or
Broadcast receiver can respond to.
Syntax of Intent Filters:
• <activity android:name=".MainActivity">
• <intent-filter
• android:icon="@drawable/icon" android:label="@string/label" >
• <action android:name="android.intent.action.MAIN" />
• <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
• </activity>
What are icons and labels
• icon: This is displayed as icon for activity. You can check or save png
image of name icon in drawable folder.
android:icon="@drawable/icon"
• • label: The label / title that appears at top in Toolbar of that
particular Activity. You can check or edit label name by opening String
XML file present inside Values folder
android:label = "@string/label“ or android:label = "New Activity“
Just like icon attribute, if you have not declared any label for your
activity then it will be same as your parent activity
• Elements In Intent Filter:
• There are following three elements in an intent filter:
• 1.Action
• 2.Data
• 3.Category
Action
Examples
Data
Activity Lifecycle:
• Activity is a screen that user interact with. Every Activity in android
has lifecycle like created, started, resumed, paused, stopped or
destroyed. These different states are known as Activity Lifecycle.
• onCreate() – Called when the activity is first created
• onStart() – Called just after it’s creation or by restart method after
onStop(). Here Activity start becoming visible to user
• onResume() – Called when Activity is visible to user and user can interact
with it .
• onPause() – Called when Activity content is not visible because user
resume previous activity.
• onStop() – Called when activity is not visible to user because some other
activity takes place of it
• onRestart() – Called when user comes on screen or resume the activity
which was stopped
• onDestroy – Called when Activity is not in background
Broadcast Receiver
• Broadcast Receiver is a component which will allow android system or
other apps to deliver events to the app like sending a low battery
message or screen turned off message to the app. The apps can also
initiate broadcasts to let other apps know that required data available
in a device to use it.
• Generally, we use Intents to deliver broadcast events to other apps
and Broadcast Receivers use status bar notifications to let user know
that broadcast event occurs.
• is implemented as a subclass of Broadcast Receiver and each
broadcast is delivered as an Intent object.
Two important steps to make
BroadcastReceiver:
• Registering Broadcast Receiver
• • Creating the Broadcast Receiver
• A broadcast receiver is implemented as a subclass of BroadcastReceiver
class and overriding the onReceive() method where each message is
received as a Intent object parameter.
• Example-
public class MyReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Intent Detected.",
Toast.LENGTH_LONG).show(); } }
System generated events are:
• android.intent.action.BATTERY_CHANGED
• • android.intent.action.BATTERY_LOW
• • android.intent.action.BATTERY_OKAY
• • android.intent.action.BOOT_COMPLETED
• • android.intent.action.BUG_REPORT
• • android.intent.action.CALL
• • android.intent.action.CALL_BUTTON
• • android.intent.action.DATE_CHANGED
• • android.intent.action.REBOOT
Create Button click Event
Registered this button to event
Go to your xml file
Create intent instance , set action , set flag,
send intent
Create another app for Receiving
Receiver app is not registered yet
‘’’’’’’’’’’’’’’’’’’’’’’
Content Provider:
• Content Provider will act as a central repository to store the applications
data in one place and make that data available for different applications to
access whenever it’s required.
• the Content Provider is a part of an android application and it will act as
more like relational database to store the app data. We can perform a
multiple operations like insert, update, delete and edit on the data stored
in content provider using insert(), update(), delete() and query() methods.
• content provider is having different ways to store app data. The app data
can be stored in a SQLite database or in files or even over a network based
on our requirements. By using content providers we can manage data such
as audio, video, images and personal contact information.
• ContentResolverTo access a data from content provider, we need to use Content Resolver
• Cursor Loader is used to run the query asynchronously in background
• Content Provider receive a data requests from client, performs the requested actions
(create, update, delete, retrieve) and return the result.
• Content URIs: To query a content provider, you specify the query string in the form of a
URI which has following format −
content://authority/path
content:// - The string content:// is always present in the URI
authority - It represents the name of content provider
path - It represents the table’s path.
The Content Resolver object use the URI’s authority to find the appropriate provider and
send the query objects to the correct provider. After that Content Provider uses the path of
content URI to choose the right table to access.
Working
To create a content provider in android applications we
should follow below steps.
• 1. We need to create a content provider class that extends the
ContentProvider base class.
• 2. We need to define our content provider URI to access the content.
• 3. The ContentProvider class defines a six abstract methods (insert(),
update(), delete(), query(), getType()) which we need to implement all
these methods as a part of our subclass.
• 4. We need to register our content provider in AndroidManifest.xml
using tag.
Methods
• query() - It receives a request from the client. By using arguments it will get a data
from requested table and return the data as a Cursor object.
• insert() - This method will insert a new row into our content provider and it will
return the content URI for newly inserted row.
• update() - This method will update an existing rows in our content provider and it
return the number of rows updated.
• delete() - This method will delete the rows in our content provider and it return
the number of rows deleted.
• getType() - This method will return the MIME type of data to given content URI.
• onCreate() - This method will initialize our content provider. The android system
will call
• this method immediately after it creates our provider.
Data Transfer between Activities & Databases
Data Transfer between Activities & Databases
Data Transfer between Activities & Databases

More Related Content

Similar to Data Transfer between Activities & Databases

Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptBirukMarkos
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in androidOum Saokosal
 
Advance Android application development workshop day 3
Advance Android application development workshop day 3Advance Android application development workshop day 3
Advance Android application development workshop day 3cresco
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetShih-Hsiang Lin
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentOwain Lewis
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Hello android world
Hello android worldHello android world
Hello android worldeleksdev
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)TECOS
 
Android application development
Android application developmentAndroid application development
Android application developmentMd. Mujahid Islam
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intentsperpetrotech
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsqperpetrotech
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 

Similar to Data Transfer between Activities & Databases (20)

Intent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).pptIntent, Service and BroadcastReciver (2).ppt
Intent, Service and BroadcastReciver (2).ppt
 
Using intents in android
Using intents in androidUsing intents in android
Using intents in android
 
Advance Android application development workshop day 3
Advance Android application development workshop day 3Advance Android application development workshop day 3
Advance Android application development workshop day 3
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Ch5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internetCh5 intent broadcast receivers adapters and internet
Ch5 intent broadcast receivers adapters and internet
 
Android intents in android application-chapter7
Android intents in android application-chapter7Android intents in android application-chapter7
Android intents in android application-chapter7
 
Unit - III.pptx
Unit - III.pptxUnit - III.pptx
Unit - III.pptx
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Hello android world
Hello android worldHello android world
Hello android world
 
ANDROID
ANDROIDANDROID
ANDROID
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)04 programmation mobile - android - (db, receivers, services...)
04 programmation mobile - android - (db, receivers, services...)
 
Android application development
Android application developmentAndroid application development
Android application development
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Unit2
Unit2Unit2
Unit2
 
Android intent
Android intentAndroid intent
Android intent
 

More from Muhammad Sajid

Characteristics of enterprise application software
Characteristics of enterprise application softwareCharacteristics of enterprise application software
Characteristics of enterprise application softwareMuhammad Sajid
 
The Checkout and Order Process
The Checkout and Order ProcessThe Checkout and Order Process
The Checkout and Order ProcessMuhammad Sajid
 
Enhancing the User Experience
Enhancing the User ExperienceEnhancing the User Experience
Enhancing the User ExperienceMuhammad Sajid
 
Products and Categories
Products and CategoriesProducts and Categories
Products and CategoriesMuhammad Sajid
 
E-Commerce Applications Development
E-Commerce Applications Development E-Commerce Applications Development
E-Commerce Applications Development Muhammad Sajid
 
E-Commerce Applications Development
E-Commerce Applications Development E-Commerce Applications Development
E-Commerce Applications Development Muhammad Sajid
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application DevelopmentMuhammad Sajid
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMuhammad Sajid
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMuhammad Sajid
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMuhammad Sajid
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMuhammad Sajid
 
Your first Android App
Your first Android AppYour first Android App
Your first Android AppMuhammad Sajid
 
Group Aided Decision making revised
Group Aided Decision making revisedGroup Aided Decision making revised
Group Aided Decision making revisedMuhammad Sajid
 
Pakistan Studies notes
Pakistan Studies notesPakistan Studies notes
Pakistan Studies notesMuhammad Sajid
 
Components of Computing Game
Components of Computing GameComponents of Computing Game
Components of Computing GameMuhammad Sajid
 
Design Elements of Computing Game
Design Elements  of Computing GameDesign Elements  of Computing Game
Design Elements of Computing GameMuhammad Sajid
 

More from Muhammad Sajid (20)

eCommerce App Lecture
eCommerce App LectureeCommerce App Lecture
eCommerce App Lecture
 
Characteristics of enterprise application software
Characteristics of enterprise application softwareCharacteristics of enterprise application software
Characteristics of enterprise application software
 
The Checkout and Order Process
The Checkout and Order ProcessThe Checkout and Order Process
The Checkout and Order Process
 
The Shopping Basket
The Shopping BasketThe Shopping Basket
The Shopping Basket
 
Enhancing the User Experience
Enhancing the User ExperienceEnhancing the User Experience
Enhancing the User Experience
 
Products and Categories
Products and CategoriesProducts and Categories
Products and Categories
 
E-Commerce Applications Development
E-Commerce Applications Development E-Commerce Applications Development
E-Commerce Applications Development
 
E-Commerce Applications Development
E-Commerce Applications Development E-Commerce Applications Development
E-Commerce Applications Development
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application Development
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENT
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENT
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENT
 
MOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENTMOBILE APPLICATION DEVELOPMENT
MOBILE APPLICATION DEVELOPMENT
 
Your first Android App
Your first Android AppYour first Android App
Your first Android App
 
Group Aided Decision making revised
Group Aided Decision making revisedGroup Aided Decision making revised
Group Aided Decision making revised
 
Pakistan Studies notes
Pakistan Studies notesPakistan Studies notes
Pakistan Studies notes
 
Components of Computing Game
Components of Computing GameComponents of Computing Game
Components of Computing Game
 
Design Elements of Computing Game
Design Elements  of Computing GameDesign Elements  of Computing Game
Design Elements of Computing Game
 
Nature of Game
Nature of GameNature of Game
Nature of Game
 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Data Transfer between Activities & Databases

  • 1. Data Transfer between Activities & Databases Lecturer Faiz Ur Rehman University of Mianwali
  • 2. Intent • Android uses Intent for communicating between the components of an Application and also from one application to another application. • Intent are the objects which is used in android for passing the information among Activities in an Application and from one app to another also. Intent are used for communicating between the Application components and it also provides the connectivity between two apps
  • 3. Example Intent intent = new Intent(getApplicationContext(), SecondActivity.class); startActivity(intent); getApplicationContext() returns the context for your foreground activity. Android intents are mainly used to: •Start the service •Launch an activity •Display a web page •Display a list of contacts •Broadcast a message •Dial a phone call etc.
  • 5.
  • 6.
  • 7. Explicit Intent: • Explicit Intents are used to connect the application internally. • Explicit Intent work internally within an application to perform navigation and data transfer. • Example Intent intent = new Intent(getApplicationContext(), SecondActivity.class); startActivity(intent);
  • 8. Implicit Intent: • In Implicit Intents we do need to specify the name of the component. • We just specify the Action which has to be performed and further this action is handled by the component of another application. • The basic example of implicit Intent is to open any web page • Example Intent intentObj = new Intent(Intent.ACTION_VIEW); intentObj.setData(Uri.parse("https://www.abhiandroid.com")); startActivity(intentObj);
  • 9. Intent Uses in android: 1. Intent for an Activity: • Every screen in Android application represents an activity. To start a new activity you need to pass an Intent object to startActivity() method. This Intent object helps to start a new activity and passing data to the second activity.
  • 10. 2. Intent for Services: • Services work in background of an Android application and it does not require any user Interface. Intents could be used to start a Service that performs one-time task • (for example: Downloading some file)
  • 11. 3. Intent for Broadcast Receivers: • There are various message that an app receives, these messages are called as Broadcast Receivers. (For example, a broadcast message could be initiated to intimate that the file downloading is completed and ready to use). Android system initiates some broadcast message on several events, such as System Reboot, Low Battery warning message etc. 4. Display a list of contacts 5. Dial a phone call etc.
  • 12. Intent Filter: • decide the behavior of an intent. • -Intent about the navigation of one activity to another, that can be achieve by declaring intent filter. • -We can declare an Intent Filter for an Activity in manifest file. • - Intent filters specify the type of intents that an Activity, service or Broadcast receiver can respond to.
  • 13. Syntax of Intent Filters: • <activity android:name=".MainActivity"> • <intent-filter • android:icon="@drawable/icon" android:label="@string/label" > • <action android:name="android.intent.action.MAIN" /> • <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> • </activity>
  • 14. What are icons and labels • icon: This is displayed as icon for activity. You can check or save png image of name icon in drawable folder. android:icon="@drawable/icon" • • label: The label / title that appears at top in Toolbar of that particular Activity. You can check or edit label name by opening String XML file present inside Values folder android:label = "@string/label“ or android:label = "New Activity“ Just like icon attribute, if you have not declared any label for your activity then it will be same as your parent activity
  • 15. • Elements In Intent Filter: • There are following three elements in an intent filter: • 1.Action • 2.Data • 3.Category
  • 16.
  • 17.
  • 20. Data
  • 21.
  • 22. Activity Lifecycle: • Activity is a screen that user interact with. Every Activity in android has lifecycle like created, started, resumed, paused, stopped or destroyed. These different states are known as Activity Lifecycle.
  • 23. • onCreate() – Called when the activity is first created • onStart() – Called just after it’s creation or by restart method after onStop(). Here Activity start becoming visible to user • onResume() – Called when Activity is visible to user and user can interact with it . • onPause() – Called when Activity content is not visible because user resume previous activity. • onStop() – Called when activity is not visible to user because some other activity takes place of it • onRestart() – Called when user comes on screen or resume the activity which was stopped • onDestroy – Called when Activity is not in background
  • 24.
  • 25. Broadcast Receiver • Broadcast Receiver is a component which will allow android system or other apps to deliver events to the app like sending a low battery message or screen turned off message to the app. The apps can also initiate broadcasts to let other apps know that required data available in a device to use it. • Generally, we use Intents to deliver broadcast events to other apps and Broadcast Receivers use status bar notifications to let user know that broadcast event occurs. • is implemented as a subclass of Broadcast Receiver and each broadcast is delivered as an Intent object.
  • 26. Two important steps to make BroadcastReceiver: • Registering Broadcast Receiver • • Creating the Broadcast Receiver
  • 27. • A broadcast receiver is implemented as a subclass of BroadcastReceiver class and overriding the onReceive() method where each message is received as a Intent object parameter. • Example- public class MyReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show(); } }
  • 28. System generated events are: • android.intent.action.BATTERY_CHANGED • • android.intent.action.BATTERY_LOW • • android.intent.action.BATTERY_OKAY • • android.intent.action.BOOT_COMPLETED • • android.intent.action.BUG_REPORT • • android.intent.action.CALL • • android.intent.action.CALL_BUTTON • • android.intent.action.DATE_CHANGED • • android.intent.action.REBOOT
  • 29.
  • 30.
  • 31.
  • 33. Registered this button to event Go to your xml file
  • 34. Create intent instance , set action , set flag, send intent
  • 35. Create another app for Receiving
  • 36. Receiver app is not registered yet
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 45.
  • 46.
  • 47. Content Provider: • Content Provider will act as a central repository to store the applications data in one place and make that data available for different applications to access whenever it’s required. • the Content Provider is a part of an android application and it will act as more like relational database to store the app data. We can perform a multiple operations like insert, update, delete and edit on the data stored in content provider using insert(), update(), delete() and query() methods. • content provider is having different ways to store app data. The app data can be stored in a SQLite database or in files or even over a network based on our requirements. By using content providers we can manage data such as audio, video, images and personal contact information.
  • 48.
  • 49. • ContentResolverTo access a data from content provider, we need to use Content Resolver • Cursor Loader is used to run the query asynchronously in background • Content Provider receive a data requests from client, performs the requested actions (create, update, delete, retrieve) and return the result. • Content URIs: To query a content provider, you specify the query string in the form of a URI which has following format − content://authority/path content:// - The string content:// is always present in the URI authority - It represents the name of content provider path - It represents the table’s path. The Content Resolver object use the URI’s authority to find the appropriate provider and send the query objects to the correct provider. After that Content Provider uses the path of content URI to choose the right table to access.
  • 51. To create a content provider in android applications we should follow below steps. • 1. We need to create a content provider class that extends the ContentProvider base class. • 2. We need to define our content provider URI to access the content. • 3. The ContentProvider class defines a six abstract methods (insert(), update(), delete(), query(), getType()) which we need to implement all these methods as a part of our subclass. • 4. We need to register our content provider in AndroidManifest.xml using tag.
  • 52. Methods • query() - It receives a request from the client. By using arguments it will get a data from requested table and return the data as a Cursor object. • insert() - This method will insert a new row into our content provider and it will return the content URI for newly inserted row. • update() - This method will update an existing rows in our content provider and it return the number of rows updated. • delete() - This method will delete the rows in our content provider and it return the number of rows deleted. • getType() - This method will return the MIME type of data to given content URI. • onCreate() - This method will initialize our content provider. The android system will call • this method immediately after it creates our provider.