I think I may have accidentally switched on some setting I didn't intent to in Eclipse or something. I'm working on an android game and from within the game logic, when certain events happen I send messages to the main activity to display certain things.
I have the following classes:
public class GameMessageHandler extends Handler {
public static final int DO_SOMETHING = 0;
private final WeakReference<MyActivity> myActivity;
public GameMessageHandler(MyActivity myActivity) {
this.myActivity = new WeakReference<MyActivity>(myActivity);
}
@Override
public void handleMessage(Message msg) {
if (myActivity != null) {
MyActivity activity = myActivity.get();
if (msg.what == DO_SOMETHING) {
//even if the caller only called this one time, this keeps executing forever
activity.doSomething();
}
}
}
}
public class GameEventListenerAndroid implements GameEventListener {
private Handler handler;
public GameEventListenerAndroid(GameMessageHandler gameMessageHandler){
this.handler = gameMessageHandler;
}
@Override
public void playerTookSomeAction() {
//this only gets called one time
handler.sendEmptyMessage(GameMessageHandler.DO_SOMETHING);
}
}
I KNOW this logic works because what I'm trying to run right now is from a backup I saved after I saw it work MULTIPLE times, but as I said what is happening right now is for some reason the Looper
keeps calling the message handler with the same message a million times per second and never discards the message to move on to something else.
Any help is greatly appreciated!