Reputation: 1686
I'm trying to build my first project with the andengine. things work fine so far but i have a problem with the threading model. As far as I know calculations should be done in the update thread to prevent the ui from freezing. So to make sure my calculations really take place in the updatethread I made a mock method with a for-loop to check if the screens freezes and unfortunately it does. so this is my test code:
this is how I initialize the scene:
private void init() {
engine.registerUpdateHandler(new IUpdateHandler() {
@Override
public void onUpdate(final float pSecondsElapsed) {
gamemodel.test();
}
@Override
public void reset() {
}
});
gamemodel is an object from this class:
public class Game {
public void test() {
for(int i=0;i<100000000;++i) {
}
}
}
I also tried to call the test-Method within engine.runOnUpdateThread but it did not work either.
I would except that the animations (animatedsprites) in the scene won't freeze because the test-method is not called in the UI thread. So what is acutally happening here and what is the solution?
Upvotes: 0
Views: 614
Reputation: 1686
as I found out by myself registering an updatehandler just means that the updatehandler is run within the next call of the update-method of the andengine. if you want to run a method asynchronously you have to do within an asynctask or something similar.
Upvotes: 1