My code with functioning thread (I removed most of the other code specific to my app). Enjoy!
Handler hand = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HandlerThread thread = new HandlerThread("ThreadName");
thread.start();
hand = new Handler(thread.getLooper());
hand.postDelayed(run, 1000);
}
Runnable run = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
longSwordPerSecond();
}
};
public void longSwordPerSecond() {
if (goldCount>1)
goldCount += 0.1f;
runOnUiThread(new Runnable() {
@Override
public void run() {
textGoldCount.setText(goldCount + " Gold");
}
});
hand.postDelayed(run, 1000);
}
The "runonuithread" is used to update the UI. So the math is done in the thread, and the only bit the UI does is show the result. That way the UI is not locked up by the process!