Android: How to pass arguments/parameters to DialogFragment?

In this short post I will show you how to dynamically provide arguments to DialogFragment from another Fragment or Activity.


Let’s create static public newInstance method in your DialogFragment.

    static public TestDialogFragment newInstance(String testStringArg) {
        TestDialogFragment f = new TestDialogFragment();

        // Add provided argument to Bundles
        Bundle args = new Bundle();
        args.putString("testStringArgKey", testStringArg);
        return f;

And next in the onCreateDialog method just get this argument value like in the code below.

    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        final String testStringArgValue = getArguments().getString("testStringArgKey");


Now you can pass arguments from your entry Fragment or Activity.

DialogFragment newFragment = TestDialogFragment.newInstance("BigDataETL is awesome!");

If you enjoyed this post please add the comment below or share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments