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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:02:26+00:00 2026-05-25T22:02:26+00:00

Hi fellow Android coders, that’s a problem I struggle with every time when I

  • 0

Hi fellow Android coders,

that’s a problem I struggle with every time when I make a new app. Imagine you have sub classes of Activity, ListActivity and MapActivity in your app. Now I want that every screen has the same options menu showing up when the user clicks the menu button. So I made a BaseActivity with that behavior. But because Java doesn’t allow multiple inheritance I have to write three BaseActivities for every type of Activity. That is ugly because I have three times the same code… The only solution I can think of is make some of the behavior static in one of those BaseActivities and refer to that in the other BaseActivites. But there are still a lot of duplicates… Anyone has a more elegant solution for that problem?

Cheers

  • 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-05-25T22:02:26+00:00Added an answer on May 25, 2026 at 10:02 pm

    This is one of the trade-offs for a single-inheritance language. Rather than duplicating code through inheriting various Activity sub-classes use a delegate. This is also called inheritance by delegation. You will get the features of multiple inheritance without the liabilities.

    This is a accomplished by creating a delegate class that has all the shared functionality you’d like then having the “super” class call the delegate. This will still require a small level of copy-and-paste code but it will be minimal. Wikipedia has a good example of the Delegation pattern. If you have a background in C# this form of delegation is similar but not restricted to single methods and for more than events.

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

Sidebar

Related Questions

For the Android app that I'm working on I have to do some lengthly
Avast there fellow programmers! I have the following problem: I have two rectangles overlapping
I have been developing an Android app and testing with a 1.5 AVD and
I have created an application in Android that needs to send emails to all
I have created android application now I want to launch the .Apk of that
Hi fellow android developers! I am developing an application where I have XML files
I have the new 15 version android sdk and the new admob sdk. On
hello fellow android programmers, I'm constantly running into the same problem over and over
I have follow this post to make ImageButton in android android image button The
fellow anthropoids and lily pads and paddlewheels! I'm developing a Windows desktop app in

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.