title: View not attached to window manager android crash
body: <p>There are a lot of similar post to this but I cannot seem to figure it out. This happens in multiple views when I push the back button.  They are views that are not part of my tabbarmanager</p>
  
  <p>Here is the logcat</p>
  
  <pre><code>04-30 17:02:44.657: E/WindowManager(7039): Activity com.myAppusa.TabManager has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40e909c0 that was originally added here
  04-30 17:02:44.657: E/WindowManager(7039): android.view.WindowLeaked: Activity com.myAppusa.TabManager has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40e909c0 that was originally added here
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:396)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:372)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:320)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.Window$LocalWindowManager.addView(Window.java:557)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.Dialog.show(Dialog.java:301)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.ProgressDialog.show(ProgressDialog.java:116)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.ProgressDialog.show(ProgressDialog.java:99)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.ProgressDialog.show(ProgressDialog.java:94)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.myAppusa.ActivityPersonalRewardsGfits.Gifts(ActivityPersonalRewardsGfits.java:240)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.myAppusa.ActivityPersonalRewardsGfits.onCreate(ActivityPersonalRewardsGfits.java:91)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.Activity.performCreate(Activity.java:4543)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.ActivityThread.startActivityNow(ActivityThread.java:2015)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.myAppusa.TabGroupActivity.finishFromChild(TabGroupActivity.java:50)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.Activity.finish(Activity.java:3785)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.myAppusa.TabGroupActivity.onBackPressed(TabGroupActivity.java:104)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.myAppusa.TabGroupActivity.onKeyUp(TabGroupActivity.java:89)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.KeyEvent.dispatch(KeyEvent.java:2692)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.Activity.dispatchKeyEvent(Activity.java:2398)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1894)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1271)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1271)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1271)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.widget.TabHost.dispatchKeyEvent(TabHost.java:302)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1271)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1271)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1271)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1967)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1402)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.Activity.dispatchKeyEvent(Activity.java:2393)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1894)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3633)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3606)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2718)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.os.Handler.dispatchMessage(Handler.java:99)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.os.Looper.loop(Looper.java:156)
  04-30 17:02:44.657: E/WindowManager(7039):  at android.app.ActivityThread.main(ActivityThread.java:5045)
  04-30 17:02:44.657: E/WindowManager(7039):  at java.lang.reflect.Method.invokeNative(Native Method)
  04-30 17:02:44.657: E/WindowManager(7039):  at java.lang.reflect.Method.invoke(Method.java:511)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  04-30 17:02:44.657: E/WindowManager(7039):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  04-30 17:02:44.657: E/WindowManager(7039):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here is the code for one of the pages that does this when I click back.</p>
  
  <pre><code>public class ActivityYourGift extends Activity {
      String terms;
      TextView tv_restaurantRewardsTitle;
      TextView tvGift, tvFrom, tvCaption, tvCompanyName, tvAddress, tvAddress2, tvDealerId, tvTrackingId, tvTerms, tvClose;
      ImageView ivUserImg, ivImageView;
      ImageView ivDealImg;
      String urlImg, user_img;
      public String user_id_restaurant;
      private TextView tvTerms_desc;
      private TextView tvValidUsername;
      private ImageView mbtnGiftMap;
      private String address;
      private String city;
      private String state;
      private String zip_code;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.your_gift_layout);
          tv_restaurantRewardsTitle =(TextView)findViewById(R.id.tv_restaurantRewardsTitle);
          /*set font for view*/
          //setFont();
          Intent in = getIntent();
  
          terms = in.getStringExtra("terms");
          user_img = in.getStringExtra("user_img");
          String caption = in.getStringExtra("caption");
  
  
  
          tvGift.setText(title);
          tvFrom.setText(name + " sent you this gift!");
          if (caption.length() == 0){
              tvCaption.setText("Test");
          }else{
              tvCaption.setText(caption);
          }
          tvTerms_desc.setText(terms);
          tvValidUsername.setText("Valid for " + name);
          tvDealerId.setText("");
          tvTrackingId.setText("Tracking: " + voucher);
  
  
          urlImg = "http://myApp.com";
  
  
  
          if(ivDealImg!=null){
              //new ImageDownloaderTask(mIvLogo).execute(urlImg+logo);
              int loader = R.drawable.loader;
              ImageLoader imgLoader = new ImageLoader(getApplicationContext());
              imgLoader.DisplayImage(urlImg+deal_img, loader, ivDealImg, true);
  
          }
  
          if(ActivityLogin.has_restaurant=="no" &amp;&amp; Double.parseDouble(distance) &lt; 0.1){
              showAlertDialogClaimRestaurant(getParent(), "Additional Rewards!", "Would you like to subscribe to this restaurants loyalty reward program for additional deals and savings?", true);
          }
  
          if(ivUserImg!=null){
              //new ImageDownloaderTask(mIvLogo).execute(urlImg+logo);
              int loader = R.drawable.loader;
              ImageLoader imgLoader = new ImageLoader(getApplicationContext());
              imgLoader.DisplayImage(urlImg+user_img, loader, ivUserImg, false);
          }
  
  
          mbtnGiftMap = (ImageView)findViewById(R.id.iv_map_gift);
          mbtnGiftMap.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                          Uri.parse("google.navigation:q=" + address + "+" + city + "+" + state));
                  startActivity(intent);
                  /*Intent mapintent = new Intent(ActivityYourGift.this, RestaurantMap.class);
  
                  mapintent.putExtra("zipCode", zip_code);
                  mapintent.putExtra("CityInfo", city);
                  mapintent.putExtra("AddressInfo", address);
                  Log.d("zipcode and city and address in gift", zip_code + city + address);
  
                  startActivity(mapintent);*/
              }
          });
          tvAddress.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
                          Uri.parse("google.navigation:q=" + address + "+" + city + "+" + state));
                  startActivity(intent);
              }
          });
  //      
          ivUserImg.setOnClickListener(new OnClickListener() {
              public void onClick(View view){
                  setContentView(R.layout.image_view);
                  ivImageView = (ImageView)findViewById(R.id.image_view_tab_icon);
                  /*tvClose = (TextView)findViewById(R.id.close);
                  tvClose.setOnClickListener(new OnClickListener() {
                      public void onClick(View view){
                          setContentView(R.layout.your_gift_layout);
  
                      }
                  });*/
                  if(ivImageView!=null){
                      //new ImageDownloaderTask(mIvLogo).execute(urlImg+logo);
                      int loader = R.drawable.loader;
                      ImageLoader imgLoader = new ImageLoader(getApplicationContext());
                      imgLoader.DisplayImage(urlImg+user_img, loader, ivImageView, true);
                  }
              }
  
  
          });
  
      }
  
      /* dialog check member */
      @SuppressWarnings("deprecation")
      public void showAlertDialogClaimRestaurant(Context context, String title,
              String message, Boolean status) {
          AlertDialog alertDialog = new AlertDialog.Builder(context).create();
  
          alertDialog.setTitle(title);
  
          alertDialog.setMessage(message);
  
          if (status != null)
              alertDialog
                      .setIcon((status) ? R.drawable.success : R.drawable.fail);
  
          alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              }
  
          });
  
          alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                  ClaimRestaurant();
  
  
  
              }
  
          });
          alertDialog.show();
      }
  
      @SuppressWarnings("unused")
      private void ClaimRestaurant() {
          RequestQueue queue = Volley.newRequestQueue(this);
          String url = ActivityLogin.webServiceURL;
          StringRequest postRequest = new StringRequest(Request.Method.POST, url,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          //NO RESPONSE
  
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          // error
                          //Log.i("Error.Response", error.getMessage());
  
                      }
                  }) {
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put("token", ActivityLogin.token);
                  params.put("mode", "claimRestaurant");
                  params.put("user_id", ActivityLogin.id);
                  params.put("user_id_restaurant", user_id_restaurant);
                  return params;
              }
          };
          queue.add(postRequest);
      }
  
      /* set font for view */
      @SuppressWarnings("unused")
      private void setFont() {
  
          String fontPathTitle = "fonts/MYRIADPRO-REGULAR.OTF";       
  
          Typeface tfTitle = Typeface.createFromAsset(getAssets(), fontPathTitle);        
  
          tv_restaurantRewardsTitle.setTypeface(tfTitle); 
      }
      /*alert to exit*/
      @SuppressWarnings("deprecation")
      public void showAlertDialogExit(Context context, String title,
              String message, Boolean status) {
          AlertDialog alertDialog = new AlertDialog.Builder(context).create();
  
  
          alertDialog.setTitle(title);
  
          alertDialog.setMessage(message);
  
          if (status != null)
  
              alertDialog
                      .setIcon((status) ? R.drawable.success : R.drawable.fail);
  
  
          alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              }
  
          });
  
          alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
  
          });
          // Showing Alert Message
          alertDialog.show();
      }
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
  
          if (keyCode == KeyEvent.KEYCODE_BACK) {
  
              ActivityYourGift.this.finish();
          }
  
          return super.onKeyDown(keyCode, event);
      }
  
      @SuppressWarnings("deprecation")
      public void showAlertTerms(Context context, String title,
              String message, Boolean status) {
          AlertDialog alertDialog = new AlertDialog.Builder(context).create();
  
          alertDialog.setTitle(title);
  
          alertDialog.setMessage(message);
  
          if (status != null)
              // Setting alert dialog icon
              alertDialog
                      .setIcon((status) ? R.drawable.success : R.drawable.fail);
  
  
          alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              }
  
          });
  
  
          alertDialog.show();
      }
  
  }
  </code></pre>
  
  <p>Here is ActivityPersonalRewardsGfits.java</p>
  
  <pre><code>    package com.myAppusa;
  
  /* IMPORTS REMOVED */
  
  public class ActivityPersonalRewardsGfits extends Activity implements
          OnClickListener {
      static String tab;
      Button btn_gfits, btn_rewards;
      ImageView iv_downLeft, iv_downRight;
      LinearLayout layout_gfits, layout_rewards;
      TextView tv_persionalRewardGiftTitle;
      ListView listReward, listGift;
      RewardsAdapter rewardsadapter;
      GiftsAdapter giftsadapter;
      ArrayList&lt;Gifts&gt; arraylistGifts = new ArrayList&lt;Gifts&gt;();
      ArrayList&lt;Rewards&gt; arrayRewards = new ArrayList&lt;Rewards&gt;();
      ProgressDialog pdialog;
      AlertDialogManager alert = new AlertDialogManager();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.personal_reward_gifts);
  
          /* Init view */
          btn_gfits = (Button) findViewById(R.id.btn_gifts);
          btn_rewards = (Button) findViewById(R.id.btn_rewards);
  
          iv_downLeft = (ImageView) findViewById(R.id.iv_dropLeft);
          iv_downRight = (ImageView) findViewById(R.id.iv_dropRight);
  
          layout_gfits = (LinearLayout) findViewById(R.id.layout_gfits);
          layout_rewards = (LinearLayout) findViewById(R.id.layout_rewards);
          tv_persionalRewardGiftTitle = (TextView) findViewById(R.id.tv_persionalRewardGiftTitle);
  
          /* set onclick Button */
          btn_gfits.setOnClickListener(this);
          btn_rewards.setOnClickListener(this);
  
          if(tab=="rewards"){
              loadRewards();
          }else{
              Gifts();
          }
          // Pass results to ListViewAdapter Class
          giftsadapter = new GiftsAdapter(this, R.layout.persional_gifts_items, arraylistGifts);
          rewardsadapter = new RewardsAdapter(this, R.layout.persional_rewards_items, arrayRewards);
          listGift = (ListView) findViewById(R.id.lv_gfits);
          listReward = (ListView) findViewById(R.id.lv_rewards);
          // Binds the Adapter to the ListView
          //listReward.setAdapter(rewardsadapter);
          listGift.setAdapter(giftsadapter);
          listReward.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; listView, View view,
                      int position, long id) {
                  Rewards rewards = arrayRewards.get(position);
                  Intent intent = new Intent(getParent(),
                          ActivityRestaurantRewards.class);
                  TabGroupActivity parentActivity = (TabGroupActivity) getParent();
                  intent.putExtra("company_name_rewards", rewards.getCompany_name());
  
  
                  intent.putExtra("name", rewards.getName());
                  intent.putExtra("terms", rewards.getTerms());
                  intent.putExtra("reward", rewards.getReward());
  
                  parentActivity.startChildActivity("ActivityRestaurantRewards", intent);
              }
          });
          listGift.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; listView, View view, int position, long id) {
                  Gifts gifts = arraylistGifts.get(position);
                  Intent intent = new Intent(getParent(), ActivityYourGift.class);
                  TabGroupActivity parentActivity = (TabGroupActivity) getParent();
                  intent.putExtra("company_name", gifts.getCompany_name());
                  intent.putExtra("deal_img", gifts.getDealImg());
                  intent.putExtra("address", gifts.getAddress());
                  intent.putExtra("city", gifts.getCity());
                  intent.putExtra("state", gifts.getState());
                  intent.putExtra("zip_code", gifts.getZipCode());
  
                  intent.putExtra("name", gifts.getName());
                  intent.putExtra("voucher", gifts.getVoucher());
                  intent.putExtra("terms", gifts.getTerms());
                  intent.putExtra("title", gifts.getTitle());
  
                  intent.putExtra("user_img", gifts.getUserImg());
                  intent.putExtra("caption", gifts.getCaption());
  
                  intent.putExtra("distance", gifts.getDistance());
                  intent.putExtra("user_id", gifts.getUserId());
  
                  parentActivity.startChildActivity("ActivityYourGift", intent);
              }
          });
  
      }
  
      private void Reward() {
          tab="rewards";
          RequestQueue queue = Volley.newRequestQueue(this);
          String url = ActivityLogin.webServiceURL;
          pdialog = ProgressDialog.show(getParent(), "", "Loading...");
          pdialog.setCancelable(true);
          StringRequest postRequest = new StringRequest(Request.Method.POST, url,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          // response
                          try {
                              JSONObject json = new JSONObject(response);
                              JSONArray items = json.getJSONArray("rewards");
                              arrayRewards = new ArrayList&lt;Rewards&gt;();
                              final String error = json.getString("error");
                              if (error.toString().equalsIgnoreCase("false")) {
                                  for (int i = 0; i &lt; items.length(); i++) {
                                      JSONObject item = items.getJSONObject(i);
  
                                      Rewards rew = new Rewards();
                                      rew.setCompany_name(item
                                              .optString("company_name"));
                                      rew.setExpiration("Expires "
                                              + item.optString("expiration"));
                                      rew.setImg(item.optString("img"));
                                      rew.setVoucher(item.optString("voucher"));
                                      rew.setPercent(item.optString("percent"));
                                      rew.setAddress(item
                                              .optString("street_address"));
                                      rew.setCity(item.optString("city"));
                                      rew.setState(item.optString("state"));
                                      rew.setZip_code(item.optString("zip_code"));
                                      rew.setName(item.optString("name"));
                                      rew.setTerms(item.optString("terms"));
                                      rew.setReward(item.optString("reward"));
                                      arrayRewards.add(rew);
                                  }
  
                                  rewardsadapter = new RewardsAdapter(
                                          ActivityPersonalRewardsGfits.this,
                                          R.layout.persional_rewards_items,
                                          arrayRewards);
                                  // Reward();
                                  listReward.setAdapter(rewardsadapter);
                              } else {
                                  alert.showAlertDialog(getParent(),
                                          "myApp alert!", error, false);
                              }
  
                          } catch (JSONException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          rewardsadapter.notifyDataSetChanged();
                          pdialog.dismiss();
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          // error
                          //Log.i("Error.Response", error.getMessage());
                          pdialog.dismiss();
                      }
                  }) {
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put("token", ActivityLogin.token);
                  params.put("mode", "getRewards");
                  params.put("user_id", ActivityLogin.id);
                  params.put("latitude", String.valueOf(ActivityLogin.latitude));
                  params.put("longitude", String.valueOf(ActivityLogin.longitude));
                  return params;
              }
          };
          queue.add(postRequest);
  
      }
  
      private void Gifts() {
          /* dialog */
          tab="gifts";
          String test = getParent().toString();
          pdialog = ProgressDialog.show(getParent(), "", "Loading...");
          pdialog.setCancelable(true);
          RequestQueue queue = Volley.newRequestQueue(this);
          String url = ActivityLogin.webServiceURL;
          StringRequest postRequest = new StringRequest(Request.Method.POST, url,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          // response
                          try {
                              JSONObject json = new JSONObject(response);
                              JSONArray items = json.getJSONArray("rewards");
                              ActivityLogin.has_restaurant = json.getString("has_restaurant");
                              arraylistGifts = new ArrayList&lt;Gifts&gt;();
                              final String error = json.getString("error");
                              if (error.toString().equalsIgnoreCase("false")) {
                                  for (int i = 0; i &lt; items.length(); i++) {
                                      JSONObject item = items.getJSONObject(i);
  
                                      Gifts gif = new Gifts();
                                      gif.setCompany_name(item.optString("company_name"));
                                      gif.setExpiration("Expires " + item.optString("expiration"));
                                      gif.setDeal_img(item.optString("deal_img"));
                                      gif.setTitle(item.optString("title"));
                                      gif.setName(item.optString("name"));
                                      gif.setUserImg(item.optString("user_img"));
                                      gif.setCaption(item.optString("caption"));
                                      gif.setTerms(item.optString("terms"));
                                      gif.setAddress(item.optString("street_address") + " " + item.optString("street_address2"));
                                      gif.setCity(item.optString("city"));
                                      gif.setState(item.optString("state"));
                                      gif.setZipCode(item.optString("zip_code"));
                                      gif.setVoucher(item.optString("voucher"));
                                      gif.setDistance(item.optString("distance"));
                                      gif.setUserId(item.optString("user_id"));
                                      arraylistGifts.add(gif);
  
                                  }
  
                                  giftsadapter = new GiftsAdapter(
                                          ActivityPersonalRewardsGfits.this,
                                          R.layout.persional_gifts_items,
                                          arraylistGifts);
                                  // Gifts();
                                  listGift.setAdapter(giftsadapter);
  
                                  if(ActivityLogin.firstLogin){
  
                                      listGift.performItemClick(listGift.getAdapter().getView(0, null, null), 0, listGift.getAdapter().getItemId(0));
                                  }
                              } else {
                                  alert.showAlertDialog(getParent(),
                                          "myApp alert!", error, false);
                              }
  
                          } catch (JSONException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          giftsadapter.notifyDataSetChanged();
                          pdialog.dismiss();
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          // error
                          //Log.i("Error.Response", error.getMessage());
                          pdialog.dismiss();
                      }
                  }) {
              @Override
              protected Map&lt;String, String&gt; getParams() {
                  Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put("token", ActivityLogin.token);
                  params.put("mode", "getGifts");
                  params.put("user_id", ActivityLogin.id);
                  params.put("latitude", String.valueOf(ActivityLogin.latitude));
                  params.put("longitude", String.valueOf(ActivityLogin.longitude));
                  return params;
              }
          };
          queue.add(postRequest);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public void onClick(View v) {
          switch (v.getId()) {
          case R.id.btn_gifts: {
  
              /* visible or invisible layout Rewards and gifts */
              layout_gfits.setVisibility(View.VISIBLE);
              layout_rewards.setVisibility(View.INVISIBLE);
  
              /* visible or invisible Image down Rewards and gifts */
              iv_downLeft.setVisibility(View.VISIBLE);
              iv_downRight.setVisibility(View.INVISIBLE);
  
              /* Change background Button tab Rewards and gifts */
              btn_gfits
                      .setBackgroundResource(R.color.activity_bar_button_selected);
              btn_rewards
                      .setBackgroundResource(R.color.activity_bar_button_unselected);
  
              /* Change TextColor Button tab Rewards and gifts */
              btn_gfits.setTextColor(Color.parseColor("#FFFFFF"));
              btn_rewards.setTextColor(Color.parseColor("#15bcdd"));
  
              // load when click
              Gifts();
  
          }
              break;
  
          case R.id.btn_rewards: {
  
              loadRewards();
  
          }
              break;
          /*
           * case R.id.iv_backScreenPersonalRewardGift:{
           * showAlertDialogExit(ActivityPersonalRewardsGfits.this,
           * "myApp alert!", "Do you want to exit myApp ?", false); }break;
           */
          }
      }
      private void loadRewards(){
          tab="rewards";
          /* visible or invisible layout Rewards and gifts */
          layout_rewards.setVisibility(View.VISIBLE);
          layout_gfits.setVisibility(View.INVISIBLE);
  
          /* visible or invisible Image down Rewards and gifts */
          iv_downLeft.setVisibility(View.INVISIBLE);
          iv_downRight.setVisibility(View.VISIBLE);
  
          /* Change background Button tab Rewards and gifts */
          btn_rewards
                  .setBackgroundResource(R.color.activity_bar_button_selected);
          btn_gfits
                  .setBackgroundResource(R.color.activity_bar_button_unselected);
  
          /* Change TextColor Button tab Rewards and gifts */
          btn_rewards.setTextColor(Color.parseColor("#FFFFFF"));
          btn_gfits.setTextColor(Color.parseColor("#15bcdd"));
  
          // load when click
  
          Reward();
  
  
      }
      /* set font for view */
      @SuppressWarnings("unused")
      private void setFont() {
          // Font path
          String fontPathTitle = "fonts/MYRIADPRO-REGULAR.OTF";
          String fontPathButton = "fonts/HelveticaNeueBold.ttf";
          // Loading Font Face
          Typeface tfTitle = Typeface.createFromAsset(getAssets(), fontPathTitle);
          Typeface tfButton = Typeface.createFromAsset(getAssets(),
                  fontPathButton);
          // Applying font
          tv_persionalRewardGiftTitle.setTypeface(tfTitle);
          btn_rewards.setTypeface(tfButton);
          btn_gfits.setTypeface(tfButton);
      }
  
  
      @SuppressWarnings("deprecation")
      public void showAlertDialogExit(Context context, String title,
              String message, Boolean status) {
          AlertDialog alertDialog = new AlertDialog.Builder(context).create();
  
          // Setting Dialog Title
          alertDialog.setTitle(title);
  
          // Setting Dialog Message
          alertDialog.setMessage(message);
  
          if (status != null)
              // Setting alert dialog icon
              alertDialog
                      .setIcon((status) ? R.drawable.success : R.drawable.fail);
  
          // Setting OK Button
          alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              }
  
          });
  
          alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
  
          });
          alertDialog.show();
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
  
  
  
          if (keyCode == KeyEvent.KEYCODE_BACK) {
              @SuppressWarnings("deprecation")
              TabActivity tabs = (TabActivity) getParent().getParent();
              //tabs.getTabHost().setCurrentTab(4);
              tabs.getTabHost().setCurrentTabByTag("tab1");
              //return false;
          }
  
          //return super.onKeyDown(keyCode, event);
  
          return true;
      }
  
      @Override
      public boolean onKeyUp(int keyCode, KeyEvent event) {
  
          return true;
      }
  
  }
  </code></pre>
  
  <p>Any help is greatly appreciated, I am new to android so don't assume I know anything. Thanks!</p>