Michal wrote: > Hello, this is as beginner as it gets. > > I'm creating an app that is basically a series of forms that collect > info from the user, and then display that info to the user as well as > allow them to modify it... very simple, almost no logic. > > I have been reading about activities, but in my test, I noticed I can > easily change what appears on the screen when my app is running simply > by using setContentView method and passing it a reference to another > layout xml resource. > > It feels "wrong" but seems to work, so I am wondering what problems > might arise from my approach. > > When exactly should an app have multiple activities? When not?
That's a little like asking when a desktop app should have multiple windows, or when a Web site should load a new page versus AJAX-ing in new content. The answer is: it depends. If you want parts of your application to be triggered and displayed by things other than the launcher icon or other parts of your app, you will want separate activities. For example, suppose you are creating a PDF viewer, and you want to allow PDF email attachments to be viewed with your viewer -- you will probably want to have the viewer independent from, say, an activity that browses the SD card for PDF files. The more you load into one activity, the more difficult it may be to handle things like rotation events (e.g., keyboard gets slid out) or eviction from RAM (e.g., implementing onSaveInstanceState() and properly restoring from it later such that the user does not notice something happened). If you want the user to be able to do two different things in your application in rapid succession (e.g., be editing one email message, then go back and look up something in another email message before continuing to edit the first), you may find this to be easier to implement with multiple activities. Those are just a few of the design criteria that might lead you in the direction of multiple activities. Now, in terms of repeatedly calling setContentView(), there you have to watch out for memory leaks. It is possible that calling setContentView() the second time will allow all widgets from the first setContentView() to be garbage-collected, but there may be other things that are holding onto them and preventing them from being collected. If so, and you keep calling setContentView(), you may continue to pile up garbage until you eventually leave the activity. If you are simply bouncing between a few "screens", consider using a TabView or ViewFlipper. -- Mark Murphy (a Commons Guy) http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---