Playback starts YouTube’s embedded player (privacy-enhanced mode).
How to Send Data to a New Fragment with a Factory Method - Android Studio Tutorial
ChannelCoding in FlowDescription from the creator
Since the Android system uses the default no-arg constructor when recreating a fragment, we should not pass values over an overloaded constructor with arguments when we instantiate it. Otherwise we get a warning that says "Avoid non-default constructors in fragments: use a default constructor plus Fragment setArguments(Bundle) instead" or we even get an InstantiationException.
The correct way to instantiate a new fragment and passing values to it, is by creating a bundle, setting arguments on this bundle and then passing it to our fragment. Inside the fragment we then retrieve this bundle and get the values out of it. A clean way to do this is by creating a so called "factory method".
Example code:
gist.github.com/codinginflow/a05784462aa8e2a609…
____________________
💻 Find the BEST programming tutorials on TutHub:
tuthub.io
⭐ Get my MVVM Caching Course now:
codinginflow.com/caching
❗ Subscribe to the channel:
youtube.com/c/codinginflo...
📨 Subscribe to the Coding in Flow newsletter:
codinginflow.com/newsletter
❓ Join our free developer community:
discord.gg/TSnMvmc
📣 Follow Coding in Flow on other sites:
Facebook: facebook.com/codinginflow
Instagram: instagram.com/codinginflow
TikTok: tiktok.com/@codinginflow
Twitter: twitter.com/codinginflow
Github: github.com/codinginflow
💰 Business requests, sponsoring, etc.: [email protected]
The correct way to instantiate a new fragment and passing values to it, is by creating a bundle, setting arguments on this bundle and then passing it to our fragment. Inside the fragment we then retrieve this bundle and get the values out of it. A clean way to do this is by creating a so called "factory method".
Example code:
gist.github.com/codinginflow/a05784462aa8e2a609…
____________________
💻 Find the BEST programming tutorials on TutHub:
tuthub.io
⭐ Get my MVVM Caching Course now:
codinginflow.com/caching
❗ Subscribe to the channel:
youtube.com/c/codinginflo...
📨 Subscribe to the Coding in Flow newsletter:
codinginflow.com/newsletter
❓ Join our free developer community:
discord.gg/TSnMvmc
📣 Follow Coding in Flow on other sites:
Facebook: facebook.com/codinginflow
Instagram: instagram.com/codinginflow
TikTok: tiktok.com/@codinginflow
Twitter: twitter.com/codinginflow
Github: github.com/codinginflow
💰 Business requests, sponsoring, etc.: [email protected]
About this tutorial
Coding in Flow published this 12:14 video tutorial on October 29, 2018. It has been watched 66,656 times on YouTube.
- Channel
- Coding in Flow
- Category
- Science & Technology
- Duration
- 12:14
- Published
- October 29, 2018
- Views
- 66,656
- Likes
- 1,054
Tags
Share
This tutorial in other languages
- FRComment envoyer des données à un nouveau fragment avec une méthode usine - Android studio Tutorial
- ESCómo enviar datos a un nuevo fragmento con un método de fábrica - Android Studio Tutorial
- PTComo enviar dados para um novo fragmento com um Factory Method - Android Estúdio Tutorial
- ITCome inviare i dati ad un nuovo frammento con un Factory Method - Android Studio Tutorial
- DEWie Daten auf ein neues Fragment mit einer Fabrik Methode senden - Android Studio Tutorial
- NLHoe om gegevens te verzenden naar een nieuw fragment met een Factory Method - Android Studio Tutorial
- RUКак отправить данные на новый фрагмент с фабричным методом - Android Studio Tutorial
- PLJak wysłać dane do nowego Fragment z metodą Factory - Android Studio Tutorial
- JAアンドロイドStudioチュートリアル - ファクトリメソッドを持つ新しいフラグメントにデータを送信する方法
- ARكيفية إرسال البيانات إلى جزء جديد مع الطريقة مصنع - الروبوت التعليمي ستوديو
- HIएंड्रॉयड स्टूडियो ट्यूटोरियल - कैसे एक फैक्टरी विधि के साथ एक नया टुकड़ा करने के लिए डेटा भेजने के लिए
- IDCara Kirim Data ke Fragmen Baru dengan Metode Pabrik - Android Studio Tutorial