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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:58:29+00:00 2026-05-23T14:58:29+00:00

The following is my situation: I have a library project and a project based

  • 0

The following is my situation:

I have a library project and a project based on it. Now in the library I have two classes A and B, whereby A uses B. In the project using the library, I have another class B, which should override the class B from the library.

But every time class A makes a call, it ends up in the class B from the library.
How can I tell Android that class B from my project should be used INSTEAD of class B from the library?

  • 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-23T14:58:29+00:00Added an answer on May 23, 2026 at 2:58 pm

    That does not work with the current layout. You have to use the strategy pattern. In your library define LibA with a constructor that takes a object of type LibB in the constructor:

    class LibA{
        LibB b;
        public LibA(LibB b)
            this.b = b;
        }
    }
    

    Then you can override LibB in your project and create LibA with the class that extends LibB:

    class ProjectB extends LibB{
    
    }
    
    LibA a = new LibA(new ProjectB());
    

    Answer to Turbos question:

    You want to start Project-Activities from your Library. So then move the code that creates the Intent into your Projects, because only in your project you know the type or name of the Activity to be started.

    The solution you mentioned in your comment (here) creates the Intent in the library project, by guessing the name of the Activity that should be started. There is nothing really wrong with that but it’s not an elegant solution. You can only start Activities that follow that special naming scheme. And because of that you cannot start arbitrary Activities that are visible in your projects like Activities from other libraries, where you cannot change the name of the class.

    To move the Intent creation into your libraries you can i.e. use the strategy, template or factory-method pattern. See Design Patterns on Wikipedia for even more (creational) patterns that match your library design.

    A simple solution would be:

    Create an abstract LibraryActivity and extend your ProjectActivities from it. The LibraryActivity defines an abstract method that returns the Intent. The implementation of that abstract method is done in your ProjectActivities.

    abstract class LibActivity{
    
        private void doSomething(){
            //Library does something
    
            //and finally calls createIntent() to start an project specific Activity
            startActivity(this.createIntent());
        }
    
        protected abstract Intent createIntent();
    }
    
    
    class ProjectActivity extends LibActivity{
    
        protected Intent createIntent(){
            return new Intent(ProjectActivity.this, AnyActivityYouWant.class);
        }        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation is following. I have shared library, which contains class definition - QueueClass :
Consider the following situation: I have two android projects named P1 and P2 which
I have the following situation: I have two threads thread1 , which is a
I have a project that produces a shared library which is linked against another,
I have the following situation: Assembly A - Class library, contains my control Control
Here is situation: I have two projects. ConsoleApp and Class Library. Console app references
I have the following situation I have one swt class which displays a simple
Imagine the following situation: I have two branches: DEV and MAIN. I'm working on
Consider the following situation: We have two Localizable.string files, one in en.lproj and one
I have the following situation: I have class User with the follwing properies :

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.