"good code" novice questions

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

"good code" novice questions

Postby sommeralex » Fri Jan 25, 2008 10:50 pm

is every screen an activity?

so, for example, if i have a login-form, a logged-in-form and so on, should every "form" be an activity?
or should i use one activity and just change the layout on it with setContentView?

thx..
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Postby Ishtar » Fri Jan 25, 2008 11:29 pm

Ya, basically every 'screen' is an acitivty. And most likely your application will consist of even more activities, that don't display anything at all. Atleast,, i think this is the way to do it... correct me if im wrong, someone? However for a login form, you can create a neat popupwindow, 2 edittexts a login button and a cancel button. I would never call setContentView twice, for 2 reasons:
1 it gives messy code
2
public View findViewById(int id)
Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).

Okay, you probably get a way with it if you process it somewhere else. But, clearly, they assume you do it only once.

Use activities for distinct things that have to be done, if you just need that little extra user input, pop up a window or dialog.

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Postby sommeralex » Fri Jan 25, 2008 11:32 pm

could you send me an example? i am still not sure what an "activity" is. i mean: for me, every function (method-invokation) is an "activity" ;-)
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby Ishtar » Fri Jan 25, 2008 11:44 pm

Hahah, now that would be a bit too much :wink:
The notepad example is very good. It depends a bit what kind of application your making. If your making something like that notepad that has a database with an object: the note as its base. You make one activity to edit it, one to view it, one to view a list of all the notes. They even got a separate activity for editting the title (a bit too much i think, maybe just to demonstrate some intent functionality).

Another example.. A IM client. You could have main activity where you can login (starts a popup), change settings. One activity as a list of all your little friends who are online, an activity as a conversation.

A good way is to think and use intents alot. Let one activity catch just a few intents. In the IM, a intent could be: start_conversation. So you need an activity for that, or send_file, or idk.. So that, another application could say: start_conversation, you could handle it, and let the user talk to the person. (Bad example maybe)

Note that, an activity still has a menu, usually, when you click a menu option, either, some little changes are made, or it fires a new intent, or shows a popup, to make some changes then.

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Postby sommeralex » Fri Jan 25, 2008 11:48 pm

thank you ;-)

-> i will do the notepad tutorial.
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby Ishtar » Fri Jan 25, 2008 11:52 pm

Your welcome. Good luck :)

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Top

Postby plusminus » Sat Jan 26, 2008 12:57 am

Hello sommeralex,

I would use a separated Activity for each different thing to do. i.e. in the :src: FriendFinder- Tutorial (ListActivity and separated MapActivity).
Google also does it like in their Notepad-Tutorial.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby sommeralex » Sat Jan 26, 2008 1:00 am

thx + good night from austria, vienna.
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Postby plusminus » Sat Jan 26, 2008 1:02 am

:lol: yes, goodnight from germany. 1 am already... :roll:

Leisure-Time was shifted to the late evening hours in the learning-time ^^

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to General

Who is online

Users browsing this forum: No registered users and 2 guests