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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:01:31+00:00 2026-06-10T13:01:31+00:00

In the Android documentation here: http://developer.android.com/guide/components/fragments.html A Fragment implements an interface. In the onAttach()

  • 0

In the Android documentation here: http://developer.android.com/guide/components/fragments.html A Fragment implements an interface.

In the onAttach() callback, it seems to cast the current Activity to an interface. Conceptually, how is this possible and is the same type of cast standard practice in vanilla Java?

public static class FragmentA extends ListFragment {


// Container Activity must implement this interface
    public interface OnArticleSelectedListener {
        public void onArticleSelected(Uri articleUri);


    OnArticleSelectedListener mListener;



    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnArticleSelectedListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener");
        }
    }
    ...
}
  • 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-10T13:01:32+00:00Added an answer on June 10, 2026 at 1:01 pm

    Some basic knowledge about the topic:

    Think about an interface as a bundle of functions. If a class implements an interface, then it guarantees, that it has all the interfaces functions implemented.

    In your case:

    If you have an object and you don’t need more than the functions of an interface, that your object implements, then you can treat (and cast) that object to that interface. This way you loose “information” about your object, because you won’t be able to use its functions (except the interface functions), but sometimes its enough.

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

Sidebar

Related Questions

The Android documentation here http://developer.android.com/guide/topics/resources/localization.html explains that you can get the current locale with
I was reading this documentation page, http://developer.android.com/reference/android/util/Log.html . The section here caught my eye:
I'm having trouble with http://developer.android.com/resources/articles/painless-threading.html It's been touted as a great source of information
i was just going through the documentation given on developer.android.com and when i was
I am using sqlitegen(http://code.google.com/p/sqlitegen/) plugin in eclipse for android. The documentation for using it
The Android Developer documentation does not mention whether the method below (and similar ones)
I've been scouring the interwebs (e.g. Android documentation, answers here, etc.) for the answer
Per the following documentation: https://developers.google.com/chrome/mobile/docs/user-agent Here is Chrome for iOS UA String: Mozilla/5.0 (iPhone;
I'm implementing IPC via Handlers in an Android application. In the official documentation (here
On Android documentation is written I can ask here about LVL problems. My Android

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.