开发者

Launching activities from Android Library when Activity is defined in the consuming App

I have an app which I am trying to turn into a library and create 2 new apps that consume it. I have to move all code differences between the 2 apps out of the library and into the separate apps due to the fact that开发者_开发知识库 I sold the source code to the client of the app. This way I can give them the library and their app. I am running into a bit of a problem tho. In at least one of my activities the UI behavior is somewhat different, in this case the CustomerListActivty. So I started to move the CustomerListActivity out into each respective app, but the problem came when other activities in the library project were trying to invoke the CustomerListActivity via startActivity(new Intent(SomeClass.this, CustomerListActivity.class));. Obviously the library no longer knew what CustomerListAcitivity was so I got compiler errors. I am at a loss on how to solve this problem. I think I need some way to refer the activity other than by class name.

Thank you for any and all help!

Aaron


Take a look at implicit intents and intent filters for when you don't want to specify exact classes and paths.


You can launch Activities without specifying the class name. You can send an Intent with an Action rather than Activity and have you Activity specify a filter for that action. It'll be launched when Action is received. The Android dev guide has a useful tutorial on how to do that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜