Handle Activity and View

Put your problem here if it does not fit any of the other categories.

Handle Activity and View

Postby lkwan2001 » Sun Oct 12, 2008 11:10 am

Hi,

I am new to Android.

I want to ask something between Activity and View.

If some logic need to be updated for each cycle, where should put the logic part? Put at Activity class with a thread?
Is that the view only control the drawing logic?

Thanks
lkwan2001
Freshman
Freshman
 
Posts: 3
Joined: Sun Oct 12, 2008 11:05 am

Top

Postby MrSnowflake » Sun Oct 12, 2008 1:00 pm

You could do it in View.draw() but I don't know it it's every 'frame' called. Another way is to make a thread and have it loop, do not forget a wait() of some sorts otherwise you'd burn trough battery power :), unless you need real-time processing.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby lkwan2001 » Sun Oct 12, 2008 6:05 pm

MrSnowflake wrote:You could do it in View.draw() but I don't know it it's every 'frame' called. Another way is to make a thread and have it loop, do not forget a wait() of some sorts otherwise you'd burn trough battery power :), unless you need real-time processing.


Do you mean I need to make a thread inside the view class? or at activity class?
If I want to create an image and have some touch key control. should these also do in the view class?

Beside when I override the onDraw method in the view class, nothing can be seen, even the log message inside the onDraw method.


More I want to ask:
If I create a Main activity to control the switching between sub-activities, can the Main activity without any view?

Thanks a lot
lkwan2001
Freshman
Freshman
 
Posts: 3
Joined: Sun Oct 12, 2008 11:05 am

Postby MrSnowflake » Sun Oct 12, 2008 6:19 pm

You need to create the Thread inside the View. And the view must be in the contentView of the activity otherwise the draw() method won't be called.
But the way you handle the logic depends on what you want. If you can share your idea with us, we can help you better in deciding which method to use. Because you could also use a Handler to post an action, without the need of a thread.

I don't see anything agains having an Activity without content. In onCreate() you start a subActivity and when that activity closes, you either kill the main app or start a new subActivity.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests