title: How to store information across Activities while using Tabs in Android
body: <p>I have made an app in which i am using <em>Two Tabs</em>, </p>
  
  <p><strong>First Tab</strong>, to show list of Products [<em>Menu Tab</em>]</p>
  
  <p><strong>Second Tab</strong>, to show products added by you [<em>Cart Tab</em>]</p>
  
  <p>Here i am allowing user to <em>add products to cart</em>, <em>update quantity for product</em> and show <em>total amount</em> of all the Items.</p>
  
  <p>In my code i am facing very small problem but i am not getting any way for last two days to resolve this.</p>
  
  <p><strong>Problem:</strong> </p>
  
  <p><em>Whenever i do click on Cart Tab to view products, those i have selected to buy and then again move back to Menu Tab to select few more products to buy and then again do click on Cart Tab to view all products i have selected, Here i am able to view Selected Product but not able to view updated quantity and not getting any change in Total Amount [Getting total of all previous added items only, not for those i have added second time...]</em></p>
  
  <p>Please tell me where i am missing, to get updated quantity and to get change in total price, what code i need to add and where i need to add in my <strong>ViewCartActivity</strong> class</p>
  
  <p><em>ViewCartActivity.Java:</em></p>
  
  <pre><code>    public class ViewCartActivity extends Activity {
  
      TextView mTxtViewGrandTotal;
      String mGrandTotal ;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) 
      {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.viewcartactivity);
  
          ListView mLstView1 = (ListView) findViewById(R.id.listView1);
          mTxtViewGrandTotal = (TextView) findViewById(R.id.mTxtViewGrandTotalValue);
  
          ViewCartAdapter mViewCartAdpt = new ViewCartAdapter(ViewCartActivity.this);
          mLstView1.setAdapter(mViewCartAdpt);
  
          if (Constants.mItem_Detail.size() &gt; 0) 
          {
              Double mGTotal = Double.parseDouble(Constants.mItem_Detail.get(0).get(SingleProductActivity.KEY_TOTAL));
              for (int i = 1; i &lt; Constants.mItem_Detail.size(); i++) {   
                  mGTotal = mGTotal + Double.parseDouble(Constants.mItem_Detail.get(i).get(SingleProductActivity.KEY_TOTAL));
              }
  
              mGrandTotal = String.valueOf(mGTotal);
              mTxtViewGrandTotal.setText(mGrandTotal);
  
  
  
              ImageButton mImgViewCart = (ImageButton) findViewById(R.id.back_btn);
              mImgViewCart.setOnClickListener(new OnClickListener() {
  
                  public void onClick(View v) {
                      // TODO Auto-generated method stub
  
                          Intent mViewCartIntent = new Intent(ViewCartActivity.this, com.version.bajrang.january.menu.ArrowsActivity.class);
                          startActivity(mViewCartIntent);
  
  
                  }
              });     
          }
      }   
  
      @Override
      protected void onResume() {
      // TODO Auto-generated method stub
      System.out.println("onResume list current size "+Constants.mItem_Detail.size());
      super.onResume();
      }
  }
  </code></pre>
  
  <p>In Logcat, i am getting:</p>
  
  <pre><code>onResume list current size 3 [Number of Records]
  </code></pre>
  
  <p><em>TabActivity.Java:</em></p>
  
  <pre><code>    private void setTabs()
  {
      addTab("Order", R.drawable.tab_order, CategoryActivity.class);
      addTab("Cart", R.drawable.tab_cart, ViewCartActivity.class);
  }
  
  @Override
      public void onBackPressed() {
      // Code to update product Quantity
      super.onBackPressed();
      Constants.mItem_Detail.clear();
  }
  </code></pre>
  
  <p><em>ViewCartAdapter.Java:</em></p>
  
  <pre><code> public class ViewCartAdapter extends BaseAdapter {
  
  Activity activity;
  LayoutInflater inflater;
  
  public ViewCartAdapter(Activity a) {
      // TODO Auto-generated constructor stub
      activity = a;
      inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  public int getCount() {
      // TODO Auto-generated method stub
      return Constants.mItem_Detail.size();
  }
  public Object getItem(int position) {
      //return position;
      return Constants.mItem_Detail.get(position);
  }
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return position;
  
  }
  public View getView(final int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      View vi = convertView;
      if (convertView == null)
          vi = inflater.inflate(R.layout.viewcartlist, null);
      TextView title = (TextView) vi.findViewById(R.id.title);
      TextView qty = (TextView) vi.findViewById(R.id.qty);
      TextView cost = (TextView) vi.findViewById(R.id.cost);
  
      HashMap&lt;String, String&gt; item = new HashMap&lt;String, String&gt;();
      item = Constants.mItem_Detail.get(position);
      // Setting all values in listview
      title.setText(item.get(SingleProductActivity.TAG_NAME));
      qty.setText(item.get(SingleProductActivity.KEY_QTY));
      cost.setText(item.get(SingleProductActivity.TAG_DURATION));
      return vi;
  }   
     }
  </code></pre>