Saving Data on Android



Download 19,28 Mb.
Pdf ko'rish
bet262/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   258   259   260   261   262   263   264   265   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Dele/ng data
One last bit of functionality that you'll add in this chapter is post deleting. Open the 
CloudFirestoreManager
 class and replace the 
TODO
 inside 
deletePost
 function 
with the following:
database.collection(POSTS_COLLECTION) 
  .document(key) 
  .delete() 
  .addOnSuccessListener { onSuccessAction() } 
  .addOnFailureListener { onFailureAction() }
To delete a post you first get a reference to the collection of the post by calling the 
collection
 method on a database instance and passing in the path to the posts 
collection. Then you get a reference to the specific post document that you want to 
delete by passing in the key which is the ID of the post. Finally, you call 
delete
 
method on a document reference which deletes the document referred to by the 
reference. The 
delete
 method deletes data asynchronously, so you also attach the 
listeners that get triggered when the deleting succeeds or fails.
Now, open the 
PostDetailsActivity
 class and inside the 
initializeClickListener
 function replace the 
TODO
 inside the delete button click 
listener with the following:
cloudFirestoreManager.deletePost(post.id, ::onPostSuccessfullyDe
leted, ::onPostDeleteFailed)
Now when you open post details you can delete post by tapping the delete button. 
You'll also test this functionality when you implement reading logic in the "Chapter 
18: Read data from Cloud Firestore".
One important thing to mention here is when you delete a post document, if that 
document contained a subcollection, that subcollection would not have been 
deleted. When you delete a document only that document is deleted; Firestore does 
not delete the documents inside the subcollections.

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   258   259   260   261   262   263   264   265   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish