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 8207295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:57:11+00:00 2026-06-07T08:57:11+00:00

Hi I was looking at the following Fragments example on the android site. http://developer.android.com/guide/components/fragments.html#Example

  • 0

Hi I was looking at the following Fragments example on the android site.

http://developer.android.com/guide/components/fragments.html#Example

I would like to know why certain methods are performed.

Why for instance, in the detailsFragment is the following method performed:

public static DetailsFragment newInstance(int index) {
    DetailsFragment f = new DetailsFragment();

    // Supply index input as an argument.
    Bundle args = new Bundle();
    args.putInt("index", index);
    f.setArguments(args);

    return f;
}

Could you not also simply instantiate the DetailsFragment and use a setter method to set index instead. Bypassing the whole setArguments.

What’s the point of using setArguments in the first place? Could you not just use setters and getters?

  • 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-07T08:57:13+00:00Added an answer on June 7, 2026 at 8:57 am

    You can use getters and setters, but by passing in a bundle you don’t need to write that code, since it’s already there. Also, I believe that these arguments are automatically passed in again if the screen orientation changes, which also makes life easier.

    Essentially, setArguments and getArguments is just a design pattern that Google suggests you follow:

    Every fragment must have an empty constructor, so it can be
    instantiated when restoring its activity’s state. It is strongly
    recommended that subclasses do not have other constructors with
    parameters, since these constructors will not be called when the
    fragment is re-instantiated; instead, arguments can be supplied by the
    caller with setArguments(Bundle) and later retrieved by the Fragment
    with getArguments().
    http://developer.android.com/reference/android/app/Fragment.html

    I take that to include setters which are needed for your Fragment to operate as well. Then again – there’s nothing forcing you to do it this way, and as you know – it’s not the only way things could be made to work.

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

Sidebar

Related Questions

I'm looking at the following API: http://wiki.github.com/soundcloud/api/oembed-api The example they give is Call: http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json
Trying to customize Symfony2 form to produce html code looking like the following example:
I'm looking at the following site: www.example.com I'm navigating to the site with a
I am looking at the following code: http://netrsc.blogspot.com/2010/04/net-c-binary-tree.html Am I right in thinking that
I'm looking at the following reference for making asynchronous web requests with C#: http://msdn.microsoft.com/en-us/library/86wf6409%28v=vs.100%29.aspx
I've been looking over the following VB code: http://www.codeproject.com/KB/vb/toggleNetworkConn.aspx If you look under The
I am looking at the following demo - http://blueimp.github.com/jQuery-File-Upload/ To my understanding in the
Im looking for a mobile SDK that has the following for iOS and Android
I have been looking at the following fiddle: Example of rounded corners It does
I'm looking at the following example Which uses the following code try { BufferedWriter

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.