Java.util.Timer and java.util.TimerTask abomination

grrr. okay so your writing an Android app and you want some bit of code to run on a semi-regular basis. So, you create a Task, something like…

private TimerTask refreshTask = new TimerTask() {
public void run() {
//do something...

…looks like a familiar design pattern, right. So in my onResume I new a Task and schedule the bloody thing and in my onPause I call Task.cancel().

…and then you run the app and it doesn’t crash right away noooooo it waits until you have to present to your boss and then it pukes all over itself, ehhem why? Well this is just one of the many unintuitive &^%*$^ that come up all the time in Java. You spend the next couple hours borking with different ways to stop and start the timer, then you spend a bit more making sure onPause and onResume are really called when they’re supposed to, and then… You figure out that not only do you have to new a Timer every time you want to restart you also have to new a TimerTask. Why!, I don’t know why, I guess they store some state in the timer task.

I’m A Curmudgeon

I admit it, not only do I use vi (vim), but I use the terminal version. Here’s is screen shot of some Braille Buzz source, notice I use clang complete (Intelligent code completion), and tagbar for navigation. Please don’t get too hung up on the code remember this was hacked together as a proof of concept, the production code will still be C but not so messy.vim colourized with ClangComplete

My .vimrc

execute pathogen#infect()
nmap :TagbarToggle

source ~/.vim/vimrcs/basic.vim
source ~/.vim/vimrcs/filetypes.vim
source ~/.vim/vimrcs/plugins_config.vim
source ~/.vim/vimrcs/extended.vim

source ~/.vim/my_configs.vim

” Highlight all instances of word under cursor, when idle.
” Useful when studying strange source code.
” Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()set hlsendif
function! AutoHighlightToggle()
let @/ = ”
if exists(‘#auto_highlight’)
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo ‘Highlight current word: off’
return 0
augroup auto_highlight
au CursorHold * let @/ = ‘\V\<'.escape(expand('‘), ‘\’).’\>’
augroup end
setl updatetime=500
echo ‘Highlight current word: ON’
return 1

flags = [