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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:44:22+00:00 2026-06-13T08:44:22+00:00

I had this problem Launching a new activity – android and don’t understand why

  • 0

I had this problem

Launching a new activity – android

and don’t understand why the original code was wrong. Also, even more confusing later on in the activity i have the following code which works using getActivity() what is the difference why does it work in one case and not the other?

public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        EditText dobText = (EditText)getActivity().findViewById(R.id.editText1);
        String dobStr = dobText.getText().toString();
        int day = Integer.valueOf(dobStr.replaceAll("([0-9]*)/[0-9]+/[0-9]+","$1"));
        int month = Integer.valueOf(dobStr.replaceAll("[0-9]+/([0-9]+)/[0-9]+", "$1"))-1;
        int year = Integer.valueOf(dobStr.replaceAll("[0-9]+/[0-9]+/([0-9]+)", "$1"));
        return new DatePickerDialog(getActivity(),this, year,month,day);
    }

}

and how is my case in the previous question different to this one

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

(search for “intent.setClass(getActivity(), DetailsActivity.class);” to find the example I’m referring to)

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

    In this example you are extending DialogFragment, this does not extend from Activity but Fragment.

    Here you are calling the getActivity() method of Fragment which returns the attached Activity object for the Fragment.

    In the previous question the class was extending Activity, so ‘this‘ is a reference to an Activity.

    The complication arises because in the previous question you were accessing ‘this‘ from an anonymous inner class, which dosen’t extend from Activity so to access the enclosing object you have to specify the name of the enclosing class i.e MainActivity.this.

    Here’s the Oracle tutorial on inner classes, the syntax can be confusing at first.

    http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html

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

Sidebar

Related Questions

I had this problem before and can't for life of me remember how to
I had this problem some time ago and I gave up but lately it
I have had this problem crop up a few times and I can't figure
Has anyone had this problem? I deleted a column in the table editor and
I know I've had this problem before so I'm really frustrated. I've got the
I have had this problem w/ two seperate WYSWYG editors in my rails application
Has anyone had this problem? My projects tend to have some long XML files
I'm very confused and am hoping someone might have had this problem and be
I had this weird problem a little while ago and haven't been able to
Seems like just yesterday I had this same problem with Play! v1. After trying

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.