• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps newbie - multi-threaded project

dsgd47

Lurker
I am new to writing Android programs.

I need to create a program that has three running threads:
1. A continually running process that monitors user interactions
2. A process that is called every 200 msec to check system status.
3. A process that monitors the UDP channel (or runs other blocking calls).

All three processes need to continue to run even if there are no incoming messages on the UDP port, or if I change the wait time.

I can handle the communications monitoring, but I need help setting up the multi-threaded part.

Can someone direct me to a COMPLETE sample project that shows how to set up such multi-threaded program? I have had people direct me to code snippets, but there is always something left out and I have not been able to get them to compile and run.

(For example, the UDP samples that people supply always talk to themselves, and not to other devices, so they don't worry about blocking calls and there is no check to see if it really went out over the network.)

Thanks,
Dan
 
There's a function in Linux that allows an app to tell Linux to callback if something particular happens. That keeps the program from using CPU to poll the event. (It's why the alarm function in Android can have a dozen alarms without affecting battery use.) I suggest you look into that - it'll make your program faster and it'll eat less battery. That's the kind of thing that makes the difference between "meh" and "wow".
 
That function is common in almost all systems. It does not seems to apply to the UDP functions. The only way that I have found to read the UDP channel is using a blocking call. I also have not found how to set up a dispatch timer. That is why I am asking for someone to show me a working example that I can modify and recompile.
 
Back
Top Bottom