[android-beginners] Re: How to make a child activity?
I dont understand why everyone makes this so complicated. First of all, this is a phone, you don't want to be using tons of data structures. There is nothing wrong with some global variables/ functions. If you want to store data that will be shared between activities, just simply use a static class with all static methods. Then you don't need a singleton or anything else fancy. It will act as a global reference, with the benefit of having its own namespace too. There is no need to do all this fancy programming stuff when you are writing for an embedded device! Master View Controller is way overboard! Just do code to get the job done (but still clean code of course). Just because you CAN do something doesn't mean you should. Or even if it's recommended that it's the best way to do it, especially on a mobile platform. Windows C++ programming techniques are not really portable to this platform. -niko On Oct 16, 7:00 pm, Paul Turchenko paul.turche...@gmail.com wrote: Another way you can use to share common data between activities is having it in the Application's instance. Just create your own Application - derived class, tell Android via manifest to use it and you can easily access it from any context. Say you have MyApplication extending Application, then (after specifying that in manifest) you can access your MyApplication's instance via (MyApplication) getApplication() call from any of your activities. Perhaps the singleton pattern is more handy in your design, but just consider this approach FYI. On Oct 16, 11:22 am, vchris80 vuc...@gmail.com wrote: thanks, I feel a bit over complicate and bug-prone to manage views manually via setContentView, so I simply changed the architecture, putting the common classes of interest in a singleton (luckily this solution fits with my app design). This way I can decouple the activities and keep a common business class, leaving Android manage the views. On 15 Ott, 20:45, Yusuf Saib (T-Mobile USA) yusuf.s...@t- Mobile.com wrote: If you are more specific about what the 3+ buttons are supposed to do, we may be able to suggest alternatives. To answer your question, setContentView is needed with ActivityGroup. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. P.S. You can only make a child activity when a mommy activity and a daddy activity love each other very much enough to get married first. On Oct 15, 12:50 am, vchris80 vuc...@gmail.com wrote: hi james, thanx for reply. I try to explain what I want to achieve. It is actually very simple, but maybe I am walking on the wrong path since I think in the Windows way other than in the Android way :) My app is a window with 3 buttons (can't use tab since the buttons will increase in the future and since this is a porting from other platform and I have to follow the same UI guidelines as far as possible). Each button launch an activity and needs a reference to the main activity (parent) in order to use some common utility classes. I thought to do so by implementing the main activity as an ActivityGroup (thank to you first suggestion) and launch each child activity by getLocalActivityManager().startActivity() as I said in the previous post. But, as said, this doesn't update the screen with the new activity view. I have to explicitly call setContentView and put the child activity view (obtained by getDecorView()). Is this the right way or am I doing a mess? Then, when I finish() the child I restore the old view. On 14 Ott, 20:50, James Yum j...@google.com wrote: Hi, I'm still not sure what you're trying to achieve. Are you really trying to embed an activity within another? You can look at the TabActivity source for a pretty clean example: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... Cheers, James On Wed, Oct 14, 2009 at 1:31 AM, vchris80 vuc...@gmail.com wrote: thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller
[android-beginners] Re: How to make a child activity?
thanks, I feel a bit over complicate and bug-prone to manage views manually via setContentView, so I simply changed the architecture, putting the common classes of interest in a singleton (luckily this solution fits with my app design). This way I can decouple the activities and keep a common business class, leaving Android manage the views. On 15 Ott, 20:45, Yusuf Saib (T-Mobile USA) yusuf.s...@t- Mobile.com wrote: If you are more specific about what the 3+ buttons are supposed to do, we may be able to suggest alternatives. To answer your question, setContentView is needed with ActivityGroup. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. P.S. You can only make a child activity when a mommy activity and a daddy activity love each other very much enough to get married first. On Oct 15, 12:50 am, vchris80 vuc...@gmail.com wrote: hi james, thanx for reply. I try to explain what I want to achieve. It is actually very simple, but maybe I am walking on the wrong path since I think in the Windows way other than in the Android way :) My app is a window with 3 buttons (can't use tab since the buttons will increase in the future and since this is a porting from other platform and I have to follow the same UI guidelines as far as possible). Each button launch an activity and needs a reference to the main activity (parent) in order to use some common utility classes. I thought to do so by implementing the main activity as an ActivityGroup (thank to you first suggestion) and launch each child activity by getLocalActivityManager().startActivity() as I said in the previous post. But, as said, this doesn't update the screen with the new activity view. I have to explicitly call setContentView and put the child activity view (obtained by getDecorView()). Is this the right way or am I doing a mess? Then, when I finish() the child I restore the old view. On 14 Ott, 20:50, James Yum j...@google.com wrote: Hi, I'm still not sure what you're trying to achieve. Are you really trying to embed an activity within another? You can look at the TabActivity source for a pretty clean example: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... Cheers, James On Wed, Oct 14, 2009 at 1:31 AM, vchris80 vuc...@gmail.com wrote: thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller needs to take care of adding this window to a view hierarchy, but I can't figure out how to do that. I watched the WindowManager for a suitable method but with no luck. On 13 Ott, 19:09, James Yum j...@google.com wrote: Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#open... Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get false,... so what I miss? thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: How to make a child activity?
Another way you can use to share common data between activities is having it in the Application's instance. Just create your own Application - derived class, tell Android via manifest to use it and you can easily access it from any context. Say you have MyApplication extending Application, then (after specifying that in manifest) you can access your MyApplication's instance via (MyApplication) getApplication() call from any of your activities. Perhaps the singleton pattern is more handy in your design, but just consider this approach FYI. On Oct 16, 11:22 am, vchris80 vuc...@gmail.com wrote: thanks, I feel a bit over complicate and bug-prone to manage views manually via setContentView, so I simply changed the architecture, putting the common classes of interest in a singleton (luckily this solution fits with my app design). This way I can decouple the activities and keep a common business class, leaving Android manage the views. On 15 Ott, 20:45, Yusuf Saib (T-Mobile USA) yusuf.s...@t- Mobile.com wrote: If you are more specific about what the 3+ buttons are supposed to do, we may be able to suggest alternatives. To answer your question, setContentView is needed with ActivityGroup. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. P.S. You can only make a child activity when a mommy activity and a daddy activity love each other very much enough to get married first. On Oct 15, 12:50 am, vchris80 vuc...@gmail.com wrote: hi james, thanx for reply. I try to explain what I want to achieve. It is actually very simple, but maybe I am walking on the wrong path since I think in the Windows way other than in the Android way :) My app is a window with 3 buttons (can't use tab since the buttons will increase in the future and since this is a porting from other platform and I have to follow the same UI guidelines as far as possible). Each button launch an activity and needs a reference to the main activity (parent) in order to use some common utility classes. I thought to do so by implementing the main activity as an ActivityGroup (thank to you first suggestion) and launch each child activity by getLocalActivityManager().startActivity() as I said in the previous post. But, as said, this doesn't update the screen with the new activity view. I have to explicitly call setContentView and put the child activity view (obtained by getDecorView()). Is this the right way or am I doing a mess? Then, when I finish() the child I restore the old view. On 14 Ott, 20:50, James Yum j...@google.com wrote: Hi, I'm still not sure what you're trying to achieve. Are you really trying to embed an activity within another? You can look at the TabActivity source for a pretty clean example: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... Cheers, James On Wed, Oct 14, 2009 at 1:31 AM, vchris80 vuc...@gmail.com wrote: thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller needs to take care of adding this window to a view hierarchy, but I can't figure out how to do that. I watched the WindowManager for a suitable method but with no luck. On 13 Ott, 19:09, James Yum j...@google.com wrote: Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#open... Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get
[android-beginners] Re: How to make a child activity?
hi james, thanx for reply. I try to explain what I want to achieve. It is actually very simple, but maybe I am walking on the wrong path since I think in the Windows way other than in the Android way :) My app is a window with 3 buttons (can't use tab since the buttons will increase in the future and since this is a porting from other platform and I have to follow the same UI guidelines as far as possible). Each button launch an activity and needs a reference to the main activity (parent) in order to use some common utility classes. I thought to do so by implementing the main activity as an ActivityGroup (thank to you first suggestion) and launch each child activity by getLocalActivityManager().startActivity() as I said in the previous post. But, as said, this doesn't update the screen with the new activity view. I have to explicitly call setContentView and put the child activity view (obtained by getDecorView()). Is this the right way or am I doing a mess? Then, when I finish() the child I restore the old view. On 14 Ott, 20:50, James Yum j...@google.com wrote: Hi, I'm still not sure what you're trying to achieve. Are you really trying to embed an activity within another? You can look at the TabActivity source for a pretty clean example: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... Cheers, James On Wed, Oct 14, 2009 at 1:31 AM, vchris80 vuc...@gmail.com wrote: thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller needs to take care of adding this window to a view hierarchy, but I can't figure out how to do that. I watched the WindowManager for a suitable method but with no luck. On 13 Ott, 19:09, James Yum j...@google.com wrote: Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#open... Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get false,... so what I miss? thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: How to make a child activity?
If you are more specific about what the 3+ buttons are supposed to do, we may be able to suggest alternatives. To answer your question, setContentView is needed with ActivityGroup. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. P.S. You can only make a child activity when a mommy activity and a daddy activity love each other very much enough to get married first. On Oct 15, 12:50 am, vchris80 vuc...@gmail.com wrote: hi james, thanx for reply. I try to explain what I want to achieve. It is actually very simple, but maybe I am walking on the wrong path since I think in the Windows way other than in the Android way :) My app is a window with 3 buttons (can't use tab since the buttons will increase in the future and since this is a porting from other platform and I have to follow the same UI guidelines as far as possible). Each button launch an activity and needs a reference to the main activity (parent) in order to use some common utility classes. I thought to do so by implementing the main activity as an ActivityGroup (thank to you first suggestion) and launch each child activity by getLocalActivityManager().startActivity() as I said in the previous post. But, as said, this doesn't update the screen with the new activity view. I have to explicitly call setContentView and put the child activity view (obtained by getDecorView()). Is this the right way or am I doing a mess? Then, when I finish() the child I restore the old view. On 14 Ott, 20:50, James Yum j...@google.com wrote: Hi, I'm still not sure what you're trying to achieve. Are you really trying to embed an activity within another? You can look at the TabActivity source for a pretty clean example: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;... Cheers, James On Wed, Oct 14, 2009 at 1:31 AM, vchris80 vuc...@gmail.com wrote: thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller needs to take care of adding this window to a view hierarchy, but I can't figure out how to do that. I watched the WindowManager for a suitable method but with no luck. On 13 Ott, 19:09, James Yum j...@google.com wrote: Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#open... Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get false,... so what I miss? thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: How to make a child activity?
thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller needs to take care of adding this window to a view hierarchy, but I can't figure out how to do that. I watched the WindowManager for a suitable method but with no luck. On 13 Ott, 19:09, James Yum j...@google.com wrote: Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#open... Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get false,... so what I miss? thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: How to make a child activity?
Hi, I'm still not sure what you're trying to achieve. Are you really trying to embed an activity within another? You can look at the TabActivity source for a pretty clean example: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/app/TabActivity.java;h=033fa0c8bf87b50f9400e457f64141d7ebad221a;hb=HEAD http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/app/TabActivity.java;h=033fa0c8bf87b50f9400e457f64141d7ebad221a;hb=HEAD Cheers, James On Wed, Oct 14, 2009 at 1:31 AM, vchris80 vuc...@gmail.com wrote: thank for your reply, but I still have some troubles: now I have my main activiy been a ActivityGroup and the child activity been a simple Activity. I start the child with this code: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); getLocalActivityManager().startActivity(and.mypackage.ChildActivity, startIntent); this way, in the onCreate of the child activity, I can get the parent and the activity results child of something by calling isChild() method. Fine. But the screen actually doesn't appear. The documentation of startActivity of LocalActivityManager says that The caller needs to take care of adding this window to a view hierarchy, but I can't figure out how to do that. I watched the WindowManager for a suitable method but with no luck. On 13 Ott, 19:09, James Yum j...@google.com wrote: Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#open... Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get false,... so what I miss? thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: How to make a child activity?
Hi, Those are meant for an ActivityGroup and its embedded activities, for example a TabActivity. What you might want to look into, is this introduction on opening screens (activities): http://developer.android.com/guide/appendix/faq/commontasks.html#opennewscreen Cheers, James On Tue, Oct 13, 2009 at 7:25 AM, vchris80 vuc...@gmail.com wrote: Hi all, I have a simple question: how I make an activity that is child of another? I use this code to start an activity from another: Intent startIntent = new Intent(MyMainActivity.this, ChildActivity.class); startActivity(startIntent); but on the onCreate method of ChildActivity, if I watch for getParent () I get null, and if I ask for isChild() I get false,... so what I miss? thank you --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---