---
title: "How do you supply construction arguments into a Fragment?"  
description: "How do you supply construction arguments into a Fragment?"  
author: "Hemant Patel"  
published: 2018-01-10  
canonical: https://answers.mindstick.com/qa/32786/how-do-you-supply-construction-arguments-into-a-fragment  
category: "technology"  
tags: ["android"]  
reading_time: 1 minute  

---

# How do you supply construction arguments into a Fragment?

How do you supply [construction](https://www.mindstick.com/articles/23525/new-tech-in-the-construction-industry) [arguments](https://answers.mindstick.com/qa/92535/what-are-the-different-types-of-arguments) into a [Fragment](https://www.mindstick.com/forum/34147/what-is-fragment-life-cycle-in-android)?

## Answers

### Answer by Prateek sharma

there are several ways to **instantiate** and pass the data to the **fragments**. these methods should be taken care of while using them. the recommended way is to use factory methods to do that.

it is also important to take care of how the data is passed to the **fragments**. if the values are passed directly to the fragments and when the app is moved to the background then to give space to other application the memory will be freed and the values will be **deleted** to free the space.

the better ways to do it is by using the **bundle** to pass the arguments to the fragments. the below code illustrates this phenomenon -

public static MyFragment newInstance(String name, int age) {

Bundle bundle = new Bundle();

bundle.putString("name", name);

bundle.putInt("age", age);

MyFragment fragment = new MyFragment();

fragment.setArguments(bundle);

return fragment;

}


---

Original Source: https://answers.mindstick.com/qa/32786/how-do-you-supply-construction-arguments-into-a-fragment

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
