SlideShare une entreprise Scribd logo
1  sur  24
Ch6. File, Saving States,
  and Preferences
           Browny
         30, May, 2011
Outline

• Saving Simple Application Data
• Creating and Saving Preferences
• Retrieving Shared Preferences
• Preference Activity and Framework
• Saving Activity State
• Saving and Loading Files
• Including Static File as Resources
• File Management Tools
Saving Simple Application Data

• 3 data-persistence techniques
 ‣   Shared
Preferences
(key/value
pairs,
can
be

     shared
among
applica8on
components
in
the

     same
applica8on
context,

but
not
available
to

     other
applica8ons)
 ‣   Saved
Applica2on
data
(A
pair
of
event
handlers

     used
for
saving
Ac8vity
instance
details)
 ‣   Files
Creating and Saving Preferences
•   Create or Modify a Shared Preference: call
    getSharedPreferences
•   To modify a Shared Preference use the
    SharedPreferences.Editor class
Retrieving Shared Preferences
Preference Activity and Framework
               (1/2)

• Android offers an XML-driven framework
  to create system-style preference screens
  for your applications
• 2 advantages
 ‣   Familiarity
 ‣   Integrate
se@ngs
screens
from
other

     applica8ons
into
your
applica8on’s
se@ngs

     screens
Preference Activity and Framework
               (2/2)

• 3 parts of Preference Activity Framework
 ‣   Preference
Screen
Layout
(An
XML
file
that

     defines
the
hierarchy
displayed
in
your

     Preference
Ac8vity)
 ‣   Preference
Ac2vity
(An
extension
of

     PreferenceAc(vity
that
will
be
used
to
host
your

     applica8on
preference
screens)
 ‣   Shared
Preference
Change
Listener
(An

     implementa8on
of
the

     onSharedPreferenceChangeListener
class)
Preference Screen Layout (1/2)

• Stored in the res/xml resources folder
• Nested Preference Screen elements (each
  will be represented as a selectable
  element that will display a new screen if
  clicked)
Preference Screen Layout (2/2)
• The specific attributes available for each
  preference, at least the following 4
 ‣   android:key,
android:+tle,
android:summary,

     android:defaultValue
Native Preference Controls

• CheckBoxPreference
• EditTextPreference
• ListPreference (equivalent of a spinner)
• RingtonePreference (useful when you’re
  constructing a screen to configure
  notification settings)
• Extending the Preference class
Using Intents to Import System
     Preference Screens (1/2)

• Preference hierarchies can include
  Preference Screens from other applications
  (including system Preference Screens)
• Useful for including links to relevant system
  Preference Screens within your own
  application settings
Using Intents to Import System
    Preference Screens (2/2)


• Make your own Preference Screens
  available for invocation using intent,
  simply add an Intent Filter to the manifest
  entry for the host Preference Activity
Preference Activity
•   Host the preference hierarchy defined using the
    preferences XML file (extend the
    PreferenceActivity)




•   To display the application settings hosted in this
    Activity (call startActivity or startActivityForResult)
Finding/Using Shared Preferences


• The Shared Preference values recorded
  for the options presented in a Preference
  Activity are stored against the application
  Context
Shared Preference Change Listeners
               (1/2)

• A callback
  (onSharedPreferenceChangeListener)
  whenever a particular Shared Preference
  value is added, removed, or modified
• Using this handler your application
  components can listen for changes to user
  preferences and update their UIs or
  behavior as required
Shared Preference Change Listeners
               (2/2)
Saving Activity State (1/2)

•   When:
    ‣   Want
to
save
Ac8vity
informa8on
that
doesn’t
need
to

        be
shared
with
other
components

•   How
    ‣   Call
Ac(vity.getPreferences()
without
specifying
a

        Shared
Preferences
name

•   What
    ‣   Access
to
the
returned
Shared
Preferences
map
is

        restricted
to
the
calling
Ac8vity;
each
Ac8vity
supports

        a
single
unnamed
Shared
Preferences
object
Saving Activity State (2/2)
Saving and Restoring Instance State
               (1/2)
• Saving (onSaveInstanceState event handler)
 ‣   Be
triggered
whenever
an
Ac8vity
completes
its

     ac8ve
lifecycle.
Only
when
it’s
not
being

     explicitly
finished
(with
a
call
to
finish)
Saving and Restoring Instance State
               (2/2)
• Restoring
 ‣   The
saved
Bundle
is
passed
in
to
the

     onRestoreInstanceState
and
onCreate
methods
if

     the
applica8on
is
forced
to
restart
during
a
session
Saving and Loading Files
•   Android offers openFileInput and openFileOuput to simplify
    reading and writing streams from and to local files
•   Support only those files in the current application folder;
    specifying path separators will cause an exception to be
    thrown
•   Files created using the openFileOuput method are private
    to the calling application
Including Static Files as Resources

 • Application requires external file resources,
   include them in your distribution package by
   placing them in the res/raw folder of your
   project hierarchy




• Android’s resource mechanism lets you specify
   alternative resource files for different
   languages, locations, and hardware
   configurations
File Management Tools

• Android supply some specialized utilities for
  file management that are available from the
  application Context
  ‣   deleteFile
(Enables
you
to
remove
files
created
by

      the
current
applica8on)
  ‣   fileList
(Returns
a
string
array
that
includes
all
the

      files
created
by
the
current
applica8on)

• Useful for cleaning up temporary files left
  behind if your application crashes or is killed
  unexpectedly
Thank you :)

Contenu connexe

Tendances

01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgetsSiva Kumar reddy Vasipally
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)Ahsanul Karim
 
Designing for Accessibility with ARIA
Designing for Accessibility with ARIADesigning for Accessibility with ARIA
Designing for Accessibility with ARIASencha
 
Android application-component
Android application-componentAndroid application-component
Android application-componentLy Haza
 
Introduction to Android for Quality Engineers
Introduction to Android for Quality EngineersIntroduction to Android for Quality Engineers
Introduction to Android for Quality EngineersAhmed Faidy
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & LayoutsVijay Rastogi
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfacesC.o. Nieto
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul Karim
 
Android Layout
Android LayoutAndroid Layout
Android Layoutmcanotes
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Android android layouts
Android android layoutsAndroid android layouts
Android android layoutsperpetrotech
 

Tendances (20)

01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
View groups containers
View groups containersView groups containers
View groups containers
 
Android UI Patterns
Android UI PatternsAndroid UI Patterns
Android UI Patterns
 
Android components
Android componentsAndroid components
Android components
 
Android development session 3 - layout
Android development   session 3 - layoutAndroid development   session 3 - layout
Android development session 3 - layout
 
Android UI
Android UIAndroid UI
Android UI
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
 
Designing for Accessibility with ARIA
Designing for Accessibility with ARIADesigning for Accessibility with ARIA
Designing for Accessibility with ARIA
 
Android application-component
Android application-componentAndroid application-component
Android application-component
 
Introduction to Android for Quality Engineers
Introduction to Android for Quality EngineersIntroduction to Android for Quality Engineers
Introduction to Android for Quality Engineers
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & Layouts
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation Primer
 
Android Layout
Android LayoutAndroid Layout
Android Layout
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application Development
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Android Lesson 2
Android Lesson 2Android Lesson 2
Android Lesson 2
 
Android android layouts
Android android layoutsAndroid android layouts
Android android layouts
 

Similaire à Ch6 file, saving states, and preferences

Android datastorage
Android datastorageAndroid datastorage
Android datastorageKrazy Koder
 
TechNet Live spor 1 sesjon 2 - sc-forefront 2
TechNet Live spor 1   sesjon 2 - sc-forefront 2TechNet Live spor 1   sesjon 2 - sc-forefront 2
TechNet Live spor 1 sesjon 2 - sc-forefront 2Anders Borchsenius
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behesteeHussain Behestee
 
Android Penetration Testing - Day 1
Android Penetration Testing - Day 1Android Penetration Testing - Day 1
Android Penetration Testing - Day 1Mohammed Adam
 
Module 3: Working with Jazz Source Control
Module 3: Working with Jazz Source ControlModule 3: Working with Jazz Source Control
Module 3: Working with Jazz Source ControlIBM Rational software
 
Community Tenure Recording Training Material Web Admin – User Training
Community Tenure Recording Training Material  Web Admin – User Training Community Tenure Recording Training Material  Web Admin – User Training
Community Tenure Recording Training Material Web Admin – User Training FAO
 
Android Training Ahmedabad , Android Course Ahmedabad, Android architecture
Android Training Ahmedabad , Android Course Ahmedabad, Android architectureAndroid Training Ahmedabad , Android Course Ahmedabad, Android architecture
Android Training Ahmedabad , Android Course Ahmedabad, Android architectureNicheTech Com. Solutions Pvt. Ltd.
 
Using the Corporate Geographic Data Model with Subversion
Using the Corporate Geographic Data Model with SubversionUsing the Corporate Geographic Data Model with Subversion
Using the Corporate Geographic Data Model with SubversionDebbie Wilson
 
R12 d49656 gc10-apps dba 16
R12 d49656 gc10-apps dba 16R12 d49656 gc10-apps dba 16
R12 d49656 gc10-apps dba 16zeesniper
 
Cetas - Application Development Services
Cetas - Application Development ServicesCetas - Application Development Services
Cetas - Application Development ServicesKabilan D
 
Vmware thin app architecture
Vmware thin app architectureVmware thin app architecture
Vmware thin app architecturesolarisyougood
 
Mobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfMobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfAbdullahMunir32
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfAbdullahMunir32
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 

Similaire à Ch6 file, saving states, and preferences (20)

Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
TechNet Live spor 1 sesjon 2 - sc-forefront 2
TechNet Live spor 1   sesjon 2 - sc-forefront 2TechNet Live spor 1   sesjon 2 - sc-forefront 2
TechNet Live spor 1 sesjon 2 - sc-forefront 2
 
LCM JB.pptx
LCM JB.pptxLCM JB.pptx
LCM JB.pptx
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
Android Penetration Testing - Day 1
Android Penetration Testing - Day 1Android Penetration Testing - Day 1
Android Penetration Testing - Day 1
 
Module 3: Working with Jazz Source Control
Module 3: Working with Jazz Source ControlModule 3: Working with Jazz Source Control
Module 3: Working with Jazz Source Control
 
Community Tenure Recording Training Material Web Admin – User Training
Community Tenure Recording Training Material  Web Admin – User Training Community Tenure Recording Training Material  Web Admin – User Training
Community Tenure Recording Training Material Web Admin – User Training
 
Android Training Ahmedabad , Android Course Ahmedabad, Android architecture
Android Training Ahmedabad , Android Course Ahmedabad, Android architectureAndroid Training Ahmedabad , Android Course Ahmedabad, Android architecture
Android Training Ahmedabad , Android Course Ahmedabad, Android architecture
 
Using the Corporate Geographic Data Model with Subversion
Using the Corporate Geographic Data Model with SubversionUsing the Corporate Geographic Data Model with Subversion
Using the Corporate Geographic Data Model with Subversion
 
R12 d49656 gc10-apps dba 16
R12 d49656 gc10-apps dba 16R12 d49656 gc10-apps dba 16
R12 d49656 gc10-apps dba 16
 
Cetas - Application Development Services
Cetas - Application Development ServicesCetas - Application Development Services
Cetas - Application Development Services
 
Vmware thin app architecture
Vmware thin app architectureVmware thin app architecture
Vmware thin app architecture
 
Session 1
Session 1Session 1
Session 1
 
Mobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfMobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdf
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Memory management
Memory managementMemory management
Memory management
 
Storage 8
Storage   8Storage   8
Storage 8
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
 
Angular meteor presentation
Angular meteor presentationAngular meteor presentation
Angular meteor presentation
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 

Plus de Shih-Hsiang Lin

Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageShih-Hsiang Lin
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9Shih-Hsiang Lin
 
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
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfacesShih-Hsiang Lin
 
Ch3 creating application and activities
Ch3 creating application and activitiesCh3 creating application and activities
Ch3 creating application and activitiesShih-Hsiang Lin
 
[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7Shih-Hsiang Lin
 
[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4Shih-Hsiang Lin
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homographyShih-Hsiang Lin
 
Project Hosting by Google
Project Hosting by GoogleProject Hosting by Google
Project Hosting by GoogleShih-Hsiang Lin
 
An Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelAn Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelShih-Hsiang Lin
 

Plus de Shih-Hsiang Lin (13)

Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming Language
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
 
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
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfaces
 
Ch3 creating application and activities
Ch3 creating application and activitiesCh3 creating application and activities
Ch3 creating application and activities
 
[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7[C++ GUI Programming with Qt4] chap7
[C++ GUI Programming with Qt4] chap7
 
[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4[C++ GUI Programming with Qt4] chap4
[C++ GUI Programming with Qt4] chap4
 
Function pointer
Function pointerFunction pointer
Function pointer
 
Introduction to homography
Introduction to homographyIntroduction to homography
Introduction to homography
 
Git basic
Git basicGit basic
Git basic
 
Project Hosting by Google
Project Hosting by GoogleProject Hosting by Google
Project Hosting by Google
 
An Introduction to Hidden Markov Model
An Introduction to Hidden Markov ModelAn Introduction to Hidden Markov Model
An Introduction to Hidden Markov Model
 

Dernier

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Dernier (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

Ch6 file, saving states, and preferences

  • 1. Ch6. File, Saving States, and Preferences Browny 30, May, 2011
  • 2. Outline • Saving Simple Application Data • Creating and Saving Preferences • Retrieving Shared Preferences • Preference Activity and Framework • Saving Activity State • Saving and Loading Files • Including Static File as Resources • File Management Tools
  • 3. Saving Simple Application Data • 3 data-persistence techniques ‣ Shared
Preferences
(key/value
pairs,
can
be
 shared
among
applica8on
components
in
the
 same
applica8on
context,

but
not
available
to
 other
applica8ons) ‣ Saved
Applica2on
data
(A
pair
of
event
handlers
 used
for
saving
Ac8vity
instance
details) ‣ Files
  • 4. Creating and Saving Preferences • Create or Modify a Shared Preference: call getSharedPreferences • To modify a Shared Preference use the SharedPreferences.Editor class
  • 6. Preference Activity and Framework (1/2) • Android offers an XML-driven framework to create system-style preference screens for your applications • 2 advantages ‣ Familiarity ‣ Integrate
se@ngs
screens
from
other
 applica8ons
into
your
applica8on’s
se@ngs
 screens
  • 7. Preference Activity and Framework (2/2) • 3 parts of Preference Activity Framework ‣ Preference
Screen
Layout
(An
XML
file
that
 defines
the
hierarchy
displayed
in
your
 Preference
Ac8vity) ‣ Preference
Ac2vity
(An
extension
of
 PreferenceAc(vity
that
will
be
used
to
host
your
 applica8on
preference
screens) ‣ Shared
Preference
Change
Listener
(An
 implementa8on
of
the
 onSharedPreferenceChangeListener
class)
  • 8. Preference Screen Layout (1/2) • Stored in the res/xml resources folder • Nested Preference Screen elements (each will be represented as a selectable element that will display a new screen if clicked)
  • 9. Preference Screen Layout (2/2) • The specific attributes available for each preference, at least the following 4 ‣ android:key,
android:+tle,
android:summary,
 android:defaultValue
  • 10. Native Preference Controls • CheckBoxPreference • EditTextPreference • ListPreference (equivalent of a spinner) • RingtonePreference (useful when you’re constructing a screen to configure notification settings) • Extending the Preference class
  • 11. Using Intents to Import System Preference Screens (1/2) • Preference hierarchies can include Preference Screens from other applications (including system Preference Screens) • Useful for including links to relevant system Preference Screens within your own application settings
  • 12. Using Intents to Import System Preference Screens (2/2) • Make your own Preference Screens available for invocation using intent, simply add an Intent Filter to the manifest entry for the host Preference Activity
  • 13. Preference Activity • Host the preference hierarchy defined using the preferences XML file (extend the PreferenceActivity) • To display the application settings hosted in this Activity (call startActivity or startActivityForResult)
  • 14. Finding/Using Shared Preferences • The Shared Preference values recorded for the options presented in a Preference Activity are stored against the application Context
  • 15. Shared Preference Change Listeners (1/2) • A callback (onSharedPreferenceChangeListener) whenever a particular Shared Preference value is added, removed, or modified • Using this handler your application components can listen for changes to user preferences and update their UIs or behavior as required
  • 16. Shared Preference Change Listeners (2/2)
  • 17. Saving Activity State (1/2) • When: ‣ Want
to
save
Ac8vity
informa8on
that
doesn’t
need
to
 be
shared
with
other
components • How ‣ Call
Ac(vity.getPreferences()
without
specifying
a
 Shared
Preferences
name • What ‣ Access
to
the
returned
Shared
Preferences
map
is
 restricted
to
the
calling
Ac8vity;
each
Ac8vity
supports
 a
single
unnamed
Shared
Preferences
object
  • 19. Saving and Restoring Instance State (1/2) • Saving (onSaveInstanceState event handler) ‣ Be
triggered
whenever
an
Ac8vity
completes
its
 ac8ve
lifecycle.
Only
when
it’s
not
being
 explicitly
finished
(with
a
call
to
finish)
  • 20. Saving and Restoring Instance State (2/2) • Restoring ‣ The
saved
Bundle
is
passed
in
to
the
 onRestoreInstanceState
and
onCreate
methods
if
 the
applica8on
is
forced
to
restart
during
a
session
  • 21. Saving and Loading Files • Android offers openFileInput and openFileOuput to simplify reading and writing streams from and to local files • Support only those files in the current application folder; specifying path separators will cause an exception to be thrown • Files created using the openFileOuput method are private to the calling application
  • 22. Including Static Files as Resources • Application requires external file resources, include them in your distribution package by placing them in the res/raw folder of your project hierarchy • Android’s resource mechanism lets you specify alternative resource files for different languages, locations, and hardware configurations
  • 23. File Management Tools • Android supply some specialized utilities for file management that are available from the application Context ‣ deleteFile
(Enables
you
to
remove
files
created
by
 the
current
applica8on) ‣ fileList
(Returns
a
string
array
that
includes
all
the
 files
created
by
the
current
applica8on) • Useful for cleaning up temporary files left behind if your application crashes or is killed unexpectedly

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n