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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:23:11+00:00 2026-05-20T12:23:11+00:00

Suppose I have my Android app’s source code packaged this way: src/ my/ app/

  • 0

Suppose I have my Android app’s source code packaged this way:

src/
   my/
      app/
         Module.java
         ModuleManager.java
         module/
            ModuleA.java
            ModuleB.java

where Module is:

public abstract class Module {
    public abstract void run();
}

, ModuleA and ModuleB extends Module:

public class ModuleA extends Module {
    @Override
    public void run() { /* do something */  }
}

and ModuleManager has some helper methods, among which one to retrieve all the Modules:

public class ModuleManager {

    private final static List<Module> modules;
    static {
        List<Module> tmp= new ArrayList<Module>();
        tmp.add(new ModuleA());
        tmp.add(new ModuleB());
        modules= Collections.unmodifiableList(tmp);
    }

    public static List<Module> getModules(){
        return modules;
    }
}

As you can see I manually filled the list of modules in ModuleManager. Instead, I would like it to be automatically filled with an instance of all the Module‘s subtypes in the module package.

I tried in several ways reflection-based solutions like this, which involve the use of ClassLoader::getResource(String path) to retrieve every .class file inside the module package, but it always returns an empty enumeration. I learnt this is due to the difference between Dalvik’s VM and Java SE’s one, and its optimized packaging of .class files inside classes.dex. I then tried to import the application’s apk from /data/app/ with DexClassLoader or PathClassLoader and unsuccesfully tried their getResource() method again. Anyway I think this is not the right direction, and probably this stuff was already hackish/flawed in Java, and it would be even more in Android.

Could you suggest me a way to do that?

Thank you very much.

  • 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-20T12:23:12+00:00Added an answer on May 20, 2026 at 12:23 pm

    One way to do this in a build script, after compilation but before dex is called to create classes.dex, run a small script to get the class names in modules folder and write it to say an application.properties file to read from (or strings.xml in resources).

    The disadvantage of this is it is not a pure java method you were asking for, the advantage being it will work for 2 or 10+ subclasses. Hope this helps.

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

Sidebar

Related Questions

Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose an app gets a content stream by being called with the android.intent.action.SEND filter.
I have a new android app I put on the marketplace a few days
I have three activities in my android app. First activity is main application screen
I thought I'd have a crack at building an Android app having not done
I have developed an android service. Any android app can use it's API's to
I have an Android tab application. Suppose at the third tab, I exit the
I have an Android app which by preference uses external storage if available to
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX

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.