开发者

Can an activity based application have no activity?

Assuming I have a shared activity class defined in a Library project, which does not change for any application using it and thus does not need to be subclassed, can I get a way with creating applications without subclassing this activity for them?

To better explain my qu开发者_如何学运维estion, say I have a single activity in a Library project:

public class LibActivity extends Activity {
 ...
}

And now I am creating an application using that Library project. Do I really need to create

public class AppActivity extends LibActivity {
 // totally empty!
}

Only so that the application have its own activity to be referenced in its own AndroidManifest.xml?

Can I get a way with a minimalistic approach, in which I subclass the activity only if I need to modify the library's activity core behavior?


Here is the fully qualified answer:

Yes, an activity based application doesn't have to derive an activity from the library's activity. The application simply uses the library's activity verbatim, unmodified.

Yes, I can get a way with a minimalistic approach, in which I subclass the activity only if I need to modify the library's activity core behavior.

I have been able to verify this with an AndroidManifest.xml that is identical in both the library and the application. It would be interesting to see whether some of this redundancy can be eliminated. I will experiment with this and report back.

UPDATE: Sure enough, it is possible to create a perfectly running application in which the only activity is defined in the library and the library's AndroidManifest.xml doesn't have any <application> or <activity>! This is possible if the application's AndroidManifest.xml has them.


You can reference library Activity classes directly from your application AndroidManifest.xml. Just specify the fully qualified name like so android:name="com.example.LibActivity"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜