> Well, I don't need multiple activities, What I need is: each class
> must implement its own UI ( setContentView, listeners etc + its own
> menus). inter class dependence must be minimum because these classes
> are going to be written by different people. This is my basic
> requirement. I am willing to do it by the best way, Activity or not.
>
> Right now the best I can think of for a compromised solution is to
> make a function call to the class (from inside the onPrepare..
> function)depending on the current view from the base Activity, let it
> do what it wants to the menu and return it. (only 1 class needs to
> extend Activity for this). Any other way? (I hope I'm clear, if not
> please ask me to explain!)

Implementing two separate activities will give you less inter-class
dependence than what you are describing. You get a side benefit of working
as the Android framework expects rather than trying to wrestle Android to
the ground. The key to using multiple activities is in starting them.

I am presuming that one activity (Activity A) will be in the launcher and
the other activity (Activity B) is supposed to appear based on some other
user action (button click, option menu press, etc.). In that case, the
simplest thing to do is:

1. Ensure both Activity classes are in the AndroidManifest.xml file as I
mentioned previously.

2. In Activity A, add the appropriate listener to be informed when the
user wants to see Activity B

3. In the appropriate listener, create an Intent representing Activity B,
probably using the Intent(Context packageContext, Class cls) constructor

4. After creating the Intent, call startActivity() or startSubActivity(),
depending on whether or not Activity A needs to know when the user leaves
Activity B -- you'll use the Intent from step #2 in either of those calls

You will see this pattern, or something like it, in any sample code that
involves multiple activities in the same project.

Note that Activity A never holds an instance of Activity B (or vice versa)
-- the objects are both managed by Android itself.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ -- Available Now!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to