Using an Android library project Activity within another project

前端 未结 8 1356
余生分开走
余生分开走 2020-11-30 01:37

I have an Android library project that I would like to use from within another Android project.

The library has a Activity declared in its AndroidManifest. When I t

相关标签:
8条回答
  • 2020-11-30 02:30

    I believe you must include the <activity> in your own AndroidManifest.xml -- I don't think it gets picked up from a library. I don't have my reference for that handy.

    Update: It's official solution. From the doc:

    Declaring library components in the manifest file

    In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>, and similar elements.

    Declarations should reference the library components by their fully-qualified package names, where appropriate.

    0 讨论(0)
  • 2020-11-30 02:32

    When using an activity inside the library, the activity should be declared only inside the manifest of library. The activity can be started from the main app like this:

      Intent intent = new Intent();
            intent.setClassName(this, "com.duna.remotelocklibrary.activities.MainRemoteActivity");
            startActivity(intent);
    

    I tried to start the library's activity like the following code, but i warn you: it doesn't work

      Intent intent = new Intent();
            intent.setClassName("com.duna.remotelocklibrary", "com.duna.remotelocklibrary.activities.MainRemoteActivity");
            startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题