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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:29:25+00:00 2026-05-17T17:29:25+00:00

I wish to have a single class which all of my Activity classes extend.

  • 0

I wish to have a single class which all of my Activity classes extend. I have ListActivities, Activities, MapActivities, TabActivities, etc in my App.

I have many of these different activities in my app, ~12 activities. I want each of them to have the methods which are in the parent class.

Right now, i have created 4 parent activity classes which are extended from a certain activity depending on their type(ListActivity, Activity, MapActivity, TabActivity)

I am creating a lot of redundant code – each of the 4 parent activities has almost identical code, in exception for what class activity it extends.

Here is an example that may clarify what my problem is:

  • I have an Activity: MenuScreen which extends BaseListActivity
  • BaseListActivity extends ListActivity
  • BaseListActivity contains methods and fields which i want all my activities to have access to

  • I have another Activity: HomeScreen which extends BaseActivity

  • BaseActivity extends Activity
  • BaseActivity contains the same methods and fields which are in my other Base[<type>]Activity classes(such as BaseListActivity)

these methods/fields are copy-pasted to all my Base[<type>]Activity, and seems awfully redundant to me.

Can i create a master activity class which all types of Activity classes can use as its parent? if not, am i stuck with copy and pasting this code and feeling gross/dirty about it?

  • 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-17T17:29:25+00:00Added an answer on May 17, 2026 at 5:29 pm

    Can i create a master activity class which all types of Activity classes can use as its parent?

    No, sorry.

    if not, am i stuck with copy and pasting this code and feeling gross/dirty about it?

    First, you do not need ListActivity or TabActivity. You do not need ListActivity for a ListView; you do not need TabActivity for a TabHost. That knocks things down to two base classes: Activity and MapActivity. Unfortunately, you do need to extend MapActivity to use MapView.

    For that, you can use composition to minimize redundancy. Rather than your “methods and fields which i want all my activities to have access to” being implemented on the activity, implement them on some other object, and have BaseActivity and BaseMapActivity hold onto an instance of that object. You will still need some amount of duplicate code (e.g., for lifecycle methods like onStop()), but more stuff can be located in a single class.

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

Sidebar

Related Questions

Ext-js Chart, I have a line graph, and I wish to add a single
I wish to have an If statement in my code, which tests if any
I have static data in a single table which I must serialize. I have
I have an app where users select images they wish to print, the print
We have a C/C++ project where we wish to encrypt (with GPG) every single
I have a single java bean, which is already annotated for JPA, that I
I am fairly new to Java. I have constructed a single JUnit test class
Normally you would have a single ErrorProvider for all the controls on a form;
We have two applications running on single machine,one of which is web application that
I have an ASP.NET MVC web app and on one page I wish to

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.