Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8030285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:43:00+00:00 2026-06-05T00:43:00+00:00

I understand mostly everything in this code, except when newIstance() is being used. Could

  • 0

I understand mostly everything in this code, except when newIstance() is being used. Could anyone please explain. Much appreciated.

public class DateDialogFragment extends DialogFragment {

public static String TAG = "DateDialogFragment";

static Context sContext;
static Calendar sDate;
static DateDialogFragmentListener sListener;

public static DateDialogFragment newInstance(Context context, int titleResource, Calendar date){
    DateDialogFragment dialog  = new DateDialogFragment();

sContext = context;
    sDate = date;

Bundle args = new Bundle();
args.putInt("title", titleResource);
dialog.setArguments(args);
return dialog;
   }
}

I made an edit, I guess its working differently when its static. I assume thats why I am confused. How is the method changed when its static? I don’t really see why not do it in the constructor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:43:01+00:00Added an answer on June 5, 2026 at 12:43 am

    When using fragments (any class that extends Fragment) you frequently need to pass some data. That’s achieved by using the setArguments method which receives a Bundle. Since doing so requires a lot of code (create the bundle, take into account key names, etc.), it is common to pass the data to a static method (usually called newInstance). The idea of that method is to create the arguments bundle and pass it to the Fragment; then it returns the fragment and you can put it where ever you want.

    Another advantage of using fragments that way is that when you are inserting a fragment directly in an XML layout, there must be an empty constructor (or nothing at all). If you create a fragment with a constructor (to pass its necessary data) you could get some errors regarding the missing empty constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to understand this piece of code as i m a beginner.Mostly these
I was wondering if this was possible. Mostly I want to understand what GNOME
Ok I understand that this error mostly comes from sending a method call or
I understand that CI is mostly URL segment based, but I want to have
I understand the differences between CHAR and VARCHAR, one being fixed-length and the other
EDIT: this question is mostly closed and the only problems i have with this
Could someone explain me the pretty basics of pixel and vertex shader interaction. The
Mostly, my confusion seems to be eminating from my attempts to understand security within
This is mostly for curiosity's sake. I've known for awhile that Xcode is capable
Im converting my site to utf, which is mostly done except there is legacy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.