Fix the position of emoji palette

Change-Id: I07a3912cb9fef8e28f3605de4e73a201a900e95c
diff --git a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
index 4f59611..9779c68 100644
--- a/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/EmojiPalettesView.java
@@ -84,6 +84,7 @@
 
     private TabHost mTabHost;
     private ViewPager mEmojiPager;
+    private int mCurrentPagerPosition = 0;
     private EmojiCategoryPageIndicatorView mEmojiCategoryPageIndicatorView;
 
     private KeyboardActionListener mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
@@ -507,6 +508,7 @@
         setCurrentCategoryId(newPos.first /* categoryId */, false /* force */);
         mEmojiCategory.setCurrentCategoryPageId(newPos.second /* categoryPageId */);
         updateEmojiCategoryPageIdView();
+        mCurrentPagerPosition = position;
     }
 
     @Override
@@ -569,15 +571,17 @@
 
     public void startEmojiPalettes() {
         if (DEBUG_PAGER) {
-            Log.d(TAG, "allocate emoji palettes memory");
+            Log.d(TAG, "allocate emoji palettes memory " + mCurrentPagerPosition);
         }
         mEmojiPager.setAdapter(mEmojiPalettesAdapter);
+        mEmojiPager.setCurrentItem(mCurrentPagerPosition);
     }
 
     public void stopEmojiPalettes() {
         if (DEBUG_PAGER) {
             Log.d(TAG, "deallocate emoji palettes memory");
         }
+        mEmojiPalettesAdapter.flushPendingRecentKeys();
         mEmojiPager.setAdapter(null);
     }