Henry Henrinson
Henry Henrinson

Reputation: 5392

Handling program flow for an application

I am currently trying to write a simple application very similar to this:

http://lab.andre-michelle.com/tonematrix

My main problem is that I do not know how to handle the general program flow. Traditionally, I would use a loop inside the main function that handled the drawing and updated the state and everything. The way the android framework works is a bit confusing since the access points into the program are the various onSomething() functions. This is quite confusing for a beginner.

How do I keep track of time and how do I know how when to move to the next square column?

Do I HAVE to use threads? Is there a single thread solution, similar to the single loop approach?

Upvotes: 0

Views: 359

Answers (1)

NikkyD
NikkyD

Reputation: 2284

You can use timers, they do already run in their own threads.

You can also use handlers for timed execution.

In case of the sample program u linked to, you would add something with onTouch and have a timer running in the background to periodically play the tune.

The activity lifecycle should be seen as the lifeline of your program not so much of the code in it.

How to keep track of time ?

 System.currentTimeMillis();

Upvotes: 1

Related Questions