Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
38 views
4 pages
Mad Unit 4
Uploaded by
Penugonda Sai Sharan
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save mad unit 4 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
38 views
4 pages
Mad Unit 4
Uploaded by
Penugonda Sai Sharan
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save mad unit 4 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save mad unit 4 For Later
You are on page 1
/ 4
Search
Fullscreen
A Persistent i yt RT. PART-B Essay QUESTIONS WITH SOLUTIONS i! USING APPLICATION SPECIFIC FOLDERS AND FILES o pofine file. Discuss the usage of application ‘Specific folders and files, yer? ae! ‘Model Papers, a3 jie Alea collection of records where each record od provides an nfrmai pessoa Sa deve and cn beaccesed hough set oft ton MES eel co Most ofthe applications create o dowload the ies that 0 ° fe specific to application. The aplication speci ook inemaly een. Whierering exer sag te tardondeamopatohanee ee pins and canbe mounted to computer file sytem when device is conse trouphUSB Brennen Insvacvey {eter deviees wll mplerent it 5 a sparte parton atemal storage. in ‘Security fsnot imposed on th les which ae stored on extemal storage, These files anbe accesed,overoitenor deleted tyanyapplication. The files stored on external: storage might not always be available, The application jcannot read files on external squoge when the SD cari jected or devieis mounted through computer, = «Android provides two methods through application context. They aes follows, 1 getDin() ‘This method is used to retum the file path that as path othe intemal application file storage dtectory. 2. getExternalFilesDie() ‘Tis method is used to rtur the file path that has path to the external application ile storage directory. ‘The getExternalFilesDir method was introduced in Android APL. The Environment geExtemalStorageDiretory() must te called 0 retum a path o root of extemal storage, , ‘The methods getDirand getEstemalflesDir accept Sung aguneatt spect subdietory ia which tefl needa be stored The files that are stored in application folders must be specific to parent application and are even not detected by media- scanner, Thus, they cannot be added to Media Library automatically. If ile are created or application is downloaded that need tobe added to Media Library orto be made available to other applications then move them to publi extemal storage directo 4.2. CREATING FILES, READING DATA FROM FILES, LISTING CONTENTS OF A DIRECTORY 10. Write short notes on the following, () Creating files (ii) Reading and writing data from and to files. Answer ¢ Mote Papers, 8 (Creating Fes In android fle canbe created by using openFleOurput() method. Syntax Sting FILE_NAME = "ile amp"; FiteOurputS ream os = openfileOutpu(FILE_ NAME, context MODE, PRIVATE): FilelnputSteam is = openFilelnput (FILE NAME); ‘SPECTRUM ALLIN-ONE JOURNAL FOR ENGINEERING STUDENTS ‘Scanned with CamScanner| Ri 46 MOBILE APPLICATION DEVELOPMENT (JNTU HYDERABAD) “The methods used in above code support the ile of present applieaton folder. Speifyng pat separators makes exe tin visting files isthe deft behaviour of them In order to append data to the existing file, the mode must be spent Conlon fies that are created by using openleOutput method are private by default the cling op ion, The file ean be shared in between application by using the content provider, The other metho is to sPecily com NODE WORLD READABLE orcontext MODE WORLD-WRITADLE whl erating output file in oderto make avaisble tote applications. String outputfile = ‘publicxt; FileOutputStream os = openFileOutpul(OUTPUT_FILE context MODE_WORLD_WRITABLE);, The location of files stored in sandbox can be known by calling getFilesDi. The method returns absolute path to fies hich are created by using openFileOutput, Syntax File f= getFilesDin(); Log.d("OUTPUT_PATH." ile getAbsolutesPath( ); Reading and Writing Data from and to Files In android, the data can be read and' written by using openfilelnput{) and openFileOutput( ) respectively. The method ‘openFileOutput() i used to create and save a file. After this data can be writen to the file. Whereas, the method openFilelnpa ) ‘method is used 1 open a file for reading, It returns an instance of FileInputStream. _ FilelnputStream is = openFilelnput(ile); Example A simple example to read one character from a fie i as given below, intx; String tmp =" while((x=isread())! =- 1) { ‘tmp = tmp + Character toString ((char)x);, } é: isclose(); _ /Avhete ‘sis the instance of FilelnputStream, Q11. How contents of a directory are listed? . Answer + : re 1A as Mode Papert ot ‘Thefiles or contents ofa drectory canbe displayedby wing" command, The ls command writs the comes ofspecifd ivetory ox name of specif ile tothe standard output. [ists the content of present directory if patil le or directory isnot specified. It displays all the contents in alphabetical order of filename, ‘The ls Command with Options ‘The various options of ‘Is! command are as follows, Description displays all the contents: ‘excluding the hidden folders or files (ie., dot(,) files and dot dot.) [displays all the files along with the hidden files Te displays one ile per line It displays the files in the reverse order Ttisplays the files as a comma-separated list displays only directories Te displays the files based on the time modified files) eee ‘Scanned with CamScannerstent Storage character of evry ety might be distor), Hock special le, character special le), Kaymbo wt pie special file), (local socket) ete. The next nine characters are divided into three sets. The fis set depicts creat emision the second set depicts the permission of remaining users in a group. And, the last set n of others who can access the file. The characters ofeach ofthese sets represent the read (1), write (w) and s of file. The detailed information can be displayed by using the below command, Is-1filel profile {pe deed information ofa directory canbe displayed by usiig below command, 15-d-Lmanisal manualfilel SHARED PREFERENCES - CREATING SHARED PREFERENCES, SAVING AND RETRIEVING DATA USING SHARED PREFERENCE oie. What are shared preferences? How are they created? * seower (od ape, Gods Pape 2) cgared Preferences Shared preferences are used to store the data of various primitive applications using their easy, ight weight NVP (name! pe) mechanism They are required when the usr want to store Ul state ser preferences or aplication setigs, They cers to save sets of name/value pairs of primitive data as named preferences. The various primitive types supported Sow {cred preferences include boolean, tring, oa, long and integer by making them ideal means to store current UI ste ser feroces, default values and class instance variables (Creating Shared Preferences ‘A shared preference canbe created by calling geSharedPreferences() on buen context bypassing meas anargumest- ‘ShazedPreferences spl = getSharedPreferences (PREF I, Activity. MODE_PRIVATE); shared preference canbe modified by using Sharedrefeences Editor cass. The editor object canbe rated by ling fs) on shared preferences object tha isto be modified. ‘SharedPreferences Editor ed) = spl.eit(); “The potcaype> methods are used fr inserting or updating he values accompanied with the given name, Examples editor puBoolear( "I" editor paPloaP, 19 editorputin("€", 2), editorptLong("T" 26% aoe patting textEntryval’, "Not Empty"), 13. Explain how shared preferences are used to save and retrieve the data. ruc) Answer: Model Papert, a9. Saving Shared Preferences “rhe ehared preferences are saved in sandbox of te application. Ths, they canbe easily shared Py comPonents of the spplictions, Note t,he shared preferences of one ppt anna be acesel by oer applications. The various modifications done on he er objet canbe saved by sing the aply or commit nehes Nee the apply() vetted at save the modifiations asynchronously and consi) method is used to save the moiicsions synchronously. Syatax eAlapply(); saving modiiations asynchronously eAl.commit(j; saving modifications synchronously “The appy() method most prefered method to sve shared preferences sae itis asynchronous The ccommtit() method a naa asus required. This method blocks the calling ead and returns tein case of sucessful te otherwise false is returned, SPECTRUM ALL-IN-ONE JOURNAL FOR ENGINEERING STUDENTS X u ‘Scanned with CamScanner4.8 MOBILE APPLICATION DEVELOPMENT [JNTU-HYCERABAD) ing Shared Preferences The shared preferences can be retrieved or accessed by using getSharedPrcference retrieved by using type-safe get
method. Every getter accepts a key and default value as Syntax sharedPreferences sp = getSharedPreferences("Settings", contéxt MODE_PRIVATE); Now, this can be accessed by using the below statement, String settings = SharedPreferences,getString(*KeyName'",“defaultValue"); boolean bl = mySharedPreferences.getBoolean ("bl fils); float f= mySharedPreferences,getFloat("t", 01); int d= mySharedPreferences.getint(“d", 1); ong | = mySharedPreferences.getLong("t", String sp = mySharedPreferences.getString( xtEntryVal = uments. ) method. The saved values can he A inap of the available shared preferences key values ear abtained by calling getANN() method and the availability of a specific key can be determined by calling containa( ) method. Syntax. Map
allPreferences = mySharedPreferences.getAll( ); boolean clf= mySharedPreferences.contain("It"); SHORT QUESTIONS Q1. Whatis persistent storage? Ans: For answer refer Unit-IV, Ql. Q2, Define shared preferences. Important Question Ans: For answer refer Unit-IV, 5 tmnportan Question Q3. Write about creating shared preferences. i Ans: For answer refer Unit-IV, Q6. ienportant enon ESSAY QUESTIONS ‘ ~ Q4. Define file. Discuss the usage of application specific ‘~Iders and files. Ans: For answer refer Unit-V, Q9. : important aeson Q5. Write short notes on the following, (i) Creating files r (ii) Reading and writing data from and to files. o Ans: For answer refer Unit-IV, QUO. . © enporant ue Q6. How contents of a directory are listed? : Ans: For answer refer Unit-lV, QUL Important 5 Q7. Explain how shared preferences are used to save and retrieve the data. vapor oo Ans: For answer refer Unit-IV, QL3. WARNING: xerowPhotocopying of his books CRIMINAL ct Anyone found gui is LIABLE to faghKEGAL process ‘Scanned with CamScanner on
You might also like
Unit 4
PDF
No ratings yet
Unit 4
43 pages
MAD Unit 4
PDF
No ratings yet
MAD Unit 4
12 pages
Android Chapter09 Files Preferences SQLite
PDF
No ratings yet
Android Chapter09 Files Preferences SQLite
79 pages
Android Data Storage: 5.1. Shared Preferences
PDF
No ratings yet
Android Data Storage: 5.1. Shared Preferences
44 pages
Lecture 2.1.2
PDF
No ratings yet
Lecture 2.1.2
46 pages
Android Programming: Data Persistence
PDF
No ratings yet
Android Programming: Data Persistence
51 pages
Module - 5: Persisting Data
PDF
No ratings yet
Module - 5: Persisting Data
54 pages
Android M5 S6
PDF
No ratings yet
Android M5 S6
12 pages
Part 5 MAD Notes On Storage, Database
PDF
No ratings yet
Part 5 MAD Notes On Storage, Database
19 pages
Ch4 Storage
PDF
No ratings yet
Ch4 Storage
23 pages
Android Application Development: Data Management
PDF
No ratings yet
Android Application Development: Data Management
43 pages
CH Two
PDF
No ratings yet
CH Two
75 pages
Andropiod Module 5
PDF
No ratings yet
Andropiod Module 5
27 pages
Unit Vi Working With Internet, Databases and Publishing App
PDF
No ratings yet
Unit Vi Working With Internet, Databases and Publishing App
11 pages
Data Persistance
PDF
No ratings yet
Data Persistance
31 pages
Chapter 4
PDF
No ratings yet
Chapter 4
35 pages
Persistent Data
PDF
No ratings yet
Persistent Data
20 pages
MAD GTU Study Material Presentations Unit-5 13082021072905PM
PDF
No ratings yet
MAD GTU Study Material Presentations Unit-5 13082021072905PM
6 pages
Lecture 08, File Handling, Shared Preferences
PDF
No ratings yet
Lecture 08, File Handling, Shared Preferences
40 pages
Shared Preferences App Dev
PDF
No ratings yet
Shared Preferences App Dev
21 pages
MAD Chapter Six
PDF
No ratings yet
MAD Chapter Six
28 pages
MobApp 13 - Persistent Data
PDF
No ratings yet
MobApp 13 - Persistent Data
37 pages
Unit IV
PDF
No ratings yet
Unit IV
19 pages
Module 4
PDF
No ratings yet
Module 4
17 pages
Udacity / Google Developing Android Apps Cheat Sheet: by Via
PDF
No ratings yet
Udacity / Google Developing Android Apps Cheat Sheet: by Via
4 pages
Database Sqlite Unit4
PDF
No ratings yet
Database Sqlite Unit4
36 pages
Android Unit 4
PDF
No ratings yet
Android Unit 4
35 pages
Storing and Retrieving
PDF
No ratings yet
Storing and Retrieving
19 pages
Unit 3
PDF
No ratings yet
Unit 3
2 pages
CH 4
PDF
No ratings yet
CH 4
20 pages
Mad Unit-3
PDF
No ratings yet
Mad Unit-3
32 pages
Android Unit - 4
PDF
No ratings yet
Android Unit - 4
36 pages
Androiddatastorage 2
PDF
No ratings yet
Androiddatastorage 2
34 pages
Chapter 4
PDF
No ratings yet
Chapter 4
32 pages
Data Storage in Android: Lecturer: Trần Hồng Nghi Email:
[email protected]
PDF
No ratings yet
Data Storage in Android: Lecturer: Trần Hồng Nghi Email:
[email protected]
71 pages
Wa0138.
PDF
No ratings yet
Wa0138.
14 pages
Unit 4
PDF
No ratings yet
Unit 4
37 pages
Unit Iv
PDF
No ratings yet
Unit Iv
30 pages
MAD Chapter Four
PDF
No ratings yet
MAD Chapter Four
37 pages
MAD Unit-4
PDF
No ratings yet
MAD Unit-4
5 pages
3 Memory Android
PDF
No ratings yet
3 Memory Android
7 pages
CH 4
PDF
No ratings yet
CH 4
18 pages
Chapter12-Files and Preferences - Publish
PDF
No ratings yet
Chapter12-Files and Preferences - Publish
5 pages
Unit-IV Working With Storage Database
PDF
No ratings yet
Unit-IV Working With Storage Database
14 pages
Unit 5
PDF
No ratings yet
Unit 5
8 pages
Mad Unit 4
PDF
No ratings yet
Mad Unit 4
4 pages
MAD Assignment Answers
PDF
No ratings yet
MAD Assignment Answers
23 pages
Data Files and Storage (Internal/External Storage) Smart Application Development
PDF
No ratings yet
Data Files and Storage (Internal/External Storage) Smart Application Development
21 pages
BCA TY Mobile Application Development UNIT IV Managing Data Storage
PDF
No ratings yet
BCA TY Mobile Application Development UNIT IV Managing Data Storage
6 pages
Data Persistence: Hands On
PDF
No ratings yet
Data Persistence: Hands On
47 pages
CH 4
PDF
No ratings yet
CH 4
8 pages
Android Training Lesson 8: FPT Software
PDF
No ratings yet
Android Training Lesson 8: FPT Software
28 pages
Unit V
PDF
No ratings yet
Unit V
18 pages
Android Data Storage, Retrieval & Sharing
PDF
100% (1)
Android Data Storage, Retrieval & Sharing
12 pages
Lecture 8 Database in Android
PDF
No ratings yet
Lecture 8 Database in Android
28 pages
07 Android Data Persistence PPTX 110128044311 Phpapp01
PDF
No ratings yet
07 Android Data Persistence PPTX 110128044311 Phpapp01
28 pages
07 Handout 1
PDF
No ratings yet
07 Handout 1
2 pages
Data Files and Storage: Licensed Under Creative Commons Attribution 2.5 License. All Rights Reserved
PDF
No ratings yet
Data Files and Storage: Licensed Under Creative Commons Attribution 2.5 License. All Rights Reserved
12 pages
3-Data Storage PDF
PDF
No ratings yet
3-Data Storage PDF
10 pages
156DP - Disaster Preparedness and Planning Management
PDF
100% (1)
156DP - Disaster Preparedness and Planning Management
1 page
UNIT - III: Cybercrime Mobile and Wireless Devices
PDF
No ratings yet
UNIT - III: Cybercrime Mobile and Wireless Devices
23 pages
Mad Unit 3
PDF
No ratings yet
Mad Unit 3
21 pages
156BW - Mobile Application Development
PDF
No ratings yet
156BW - Mobile Application Development
1 page