# HG changeset patch # User Philipp Wiesemann # Date 1367751034 -7200 # Node ID 4552268486f289b5e4e2250ae7c0f4ab0d798e34 # Parent c700de9c8ed451a5578a4170aae4d8758705133b Fixed possible leak and its Android Lint warning in Java file. diff -r c700de9c8ed4 -r 4552268486f2 android-project/src/org/libsdl/app/SDLActivity.java --- a/android-project/src/org/libsdl/app/SDLActivity.java Sun May 05 12:47:44 2013 +0200 +++ b/android-project/src/org/libsdl/app/SDLActivity.java Sun May 05 12:50:34 2013 +0200 @@ -24,6 +24,7 @@ SDL Activity */ public class SDLActivity extends Activity { + private static final String TAG = "SDL"; // Keep track of the paused state public static boolean mIsPaused = false; @@ -113,25 +114,41 @@ static final int COMMAND_UNUSED = 2; static final int COMMAND_TEXTEDIT_HIDE = 3; - // Handler for the messages - Handler commandHandler = new Handler() { + /** + * A Handler class for Messages from native SDL applications. + * It uses current Activities as target (e.g. for the title). + * static to prevent implicit references to enclosing object. + */ + protected static class SDLCommandHandler extends Handler { @Override public void handleMessage(Message msg) { + Context context = getContext(); + if (context == null) { + Log.e(TAG, "error handling message, getContext() returned null"); + return; + } switch (msg.arg1) { case COMMAND_CHANGE_TITLE: - setTitle((String)msg.obj); + if (context instanceof Activity) { + ((Activity) context).setTitle((String)msg.obj); + } else { + Log.e(TAG, "error handling message, getContext() returned no Activity"); + } break; case COMMAND_TEXTEDIT_HIDE: if (mTextEdit != null) { mTextEdit.setVisibility(View.GONE); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0); } break; } } - }; + } + + // Handler for the messages + Handler commandHandler = new SDLCommandHandler(); // Send a message from the SDLMain thread void sendCommand(int command, Object data) {