title: AndroidStudio: Intent Problem- Return data using Intent but no working
body: <p>I want to return the data from second activity to first activity using intent when click the OnAddClicked button in second activity, but what I done was not working. The data that I return to first activity is null and I have no idea about this. Can anyone help me to solve this problem?</p>
  <p>First Activity:</p>
  <pre><code>public class CartView extends AppCompatActivity {
  
      ActivityCartViewBinding binding;
      public CartView.MyClickHandler handler;
      GridView view_listView;
      String Default_curr;
      String itemgroup;
      String itemtype;
      String uprice;
      String quantity;
      ACDatabase db;
      List&lt;AC_Class.Item&gt; s_item = new ArrayList&lt;&gt;();
      AC_Class.InvoiceDetails invoiceDetails;
      AC_Class.Item item;
      String substring = &quot;&quot;;
      EditText searchEditText;
      Button All;
      Button Type;
      Button Group;
      ArrayAdapter&lt;String&gt; adapter;
      int i = 0;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          binding = DataBindingUtil.setContentView(this, R.layout.activity_cart_view);
  
          // Action Bar
          ActionBar actionBar = getSupportActionBar();
          actionBar.setTitle(&quot;Catalog&quot;);
          actionBar.setDisplayHomeAsUpEnabled(true);
          searchEditText = (EditText) findViewById(R.id.searchField);
          UIUtil.hideKeyboard(this);
          UIUtil.showKeyboard(this, searchEditText);
  
          db = new ACDatabase(this);
          invoiceDetails = new AC_Class.InvoiceDetails();
          item = new AC_Class.Item();
          handler = new MyClickHandler(this);
          binding.setHandler(handler);
          All = (Button) findViewById(R.id.button1);
          Type = (Button) findViewById(R.id.button2);
          Group = (Button) findViewById(R.id.button3);
          view_listView = (GridView) findViewById(R.id.GridView);
  
          All.setVisibility(View.GONE);
          Type.setVisibility(View.GONE);
          Group.setVisibility(View.GONE);
  
          getData(&quot;&quot;);
  
          searchEditText.addTextChangedListener(new TextWatcher() {
  
              @Override
              public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {}
  
              @Override
              public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
  
              @Override
              public void afterTextChanged(Editable s) {
  
                  getData(s.toString().trim());
              }
          });
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.ctlg_menu, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          int id = item.getItemId();
          /*if (id == android.R.id.home)
          {
              onBackPressed();
              return true;
          }*/
          if (id == R.id.cart)
          {
              Intent new_intent = new Intent(CartView.this, CartList.class);
              new_intent.putExtra(&quot;invoiceDetail&quot;, invoiceDetails);
              startActivityForResult(new_intent,3);
  
          }
        
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          getData(&quot;&quot;);
      }
  
      public void getData(String substring) {
          Cursor data = db.getItemLike(substring, 0);
          if (data.getCount() &gt; 0){
              s_item.clear();
              while (data.moveToNext()) {
                  try {
                      AC_Class.Item item = new AC_Class.Item(data.getString(0), data.getString(1), data.getString(2), data.getString(3), data.getString(4), data.getString(5), data.getString(6), data.getString(7), data.getString(8), data.getFloat(9), data.getFloat(10), data.getFloat(11), data.getFloat(12), data.getFloat(13), data.getFloat(14), data.getString(15), data.getString(16), data.getFloat(17), data.getString(18),data.getFloat(19),data.getFloat(20));
  
                      s_item.add(item);
                  } catch (Exception e) { Log.i(&quot;custDebug&quot;, &quot;error reading image: &quot;+e.getMessage()); }
              }
              CartViewListAdapter arrayAdapter = new CartViewListAdapter(this, s_item);
              view_listView.setAdapter(arrayAdapter);
              Cursor dcurren = db.getReg(&quot;6&quot;);
              if(dcurren.moveToFirst()){
                  Default_curr = dcurren.getString(0);
              }
              view_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                      String itemcode = ((AC_Class.Item)parent.getItemAtPosition(position)).getItemCode();
                      String uom = ((AC_Class.Item)parent.getItemAtPosition(position)).getUOM();
                      AC_Class.Item sa =((AC_Class.Item) parent.getItemAtPosition(position));
                      //Intent item_intent = new Intent();
                      Intent item_intent = new Intent(CartView.this, ItemDetail.class);
                      item_intent.putExtra(&quot;ItemKey&quot;,itemcode);
                      item_intent.putExtra(&quot;ItemUOMKey&quot;,uom);
                      item_intent.putExtra(&quot;Items&quot;,sa);
                      //setResult(4, item_intent);
                      startActivity(item_intent);
                      //finish();
                  }
              });
          }
      }
  
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          switch (requestCode) {
  
              case 1:
                  if (resultCode == 1) {
                      itemtype = data.getStringExtra(&quot;TypeKey&quot;);
  
                      if (itemtype != null) {
                          getTypedata();
                      }
                  }
                  break;
  
              case 2:
                  if (resultCode == 1) {
                      itemgroup = data.getStringExtra(&quot;GroupKey&quot;);
                      if(itemgroup != null){
                          getGroupdata();
                      }
  
                  }
                  break;
  
              case 3:
                  if (resultCode == 1) {
                      AC_Class.Item i = data.getParcelableExtra(&quot;Item&quot;);
                      uprice = data.getStringExtra(&quot;Price&quot;);
                      quantity = data.getStringExtra(&quot;Quantity&quot;);
  
                      if (i != null) {
                          invoiceDetails.setItemCode(i.getItemCode());
                          invoiceDetails.setItemDescription(i.getDescription());
                          invoiceDetails.setUPrice(Double.valueOf(i.getPrice()));
                          invoiceDetails.setUOM(i.getUOM());
                          //invoiceDetails.setUPrice(Double.valueOf(uprice));
                          invoiceDetails.setQuantity(Double.valueOf(quantity));
                      }
                  }
                  break;
          }
      }
  }
  </code></pre>
  <p>SecondActivity:</p>
  <pre><code>public class ItemDetail extends AppCompatActivity {
      ActivityItemDetailBinding binding;
      AC_Class.Item items;
      AC_Class.ItemUOM itemuom;
      AC_Class.Cart cart;
      AC_Class.InvoiceDetails invoiceDetails;
      ACDatabase db;
      String Item;
      String ItemUOM;
      String Default_curr;
      Intent pintent;
      EditText etQty;
      String default_loc;
      List&lt;AC_Class.Item&gt; c_item = new ArrayList&lt;&gt;();
      MyClickHandler handler;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          binding = DataBindingUtil.setContentView(this, R.layout.activity_item_detail);
  
          itemuom = new AC_Class.ItemUOM();
          items = new AC_Class.Item();
          invoiceDetails = new AC_Class.InvoiceDetails();
          cart = new AC_Class.Cart();
          ActionBar actionBar = getSupportActionBar();
          actionBar.setDisplayHomeAsUpEnabled(true);
          db = new ACDatabase(this);
          pintent = getIntent();
          //substring = pintent.getStringExtra(&quot;substring&quot;);
          Item = pintent.getStringExtra(&quot;ItemKey&quot;);
          ItemUOM = pintent.getStringExtra(&quot;ItemUOMKey&quot;);
  
          handler = new MyClickHandler(this);
          binding.setHandler(handler);
  
          Cursor loc = db.getReg(&quot;7&quot;);
          if(loc.moveToFirst()){
              default_loc = loc.getString(0);
          }
       
          items = pintent.getParcelableExtra(&quot;Items&quot;);
          binding.setItem(items);
          
          binding.setInvoicedetail(invoiceDetails);
  
       
  
  
          binding.quantity.addTextChangedListener(new TextWatcher() {
              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
              }
  
              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
                  etQty = (EditText)findViewById(R.id.quantity);
  
                  String qty = etQty.getText().toString();
  
                  if(qty.length() &gt; 0)
                  {
                      invoiceDetails.setQuantity(Double.valueOf(qty));
                      //Calculation();
                  }
              }
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
              case android.R.id.home: {
                  onBackPressed();
                  return true;
              }
          }
          return super.onOptionsItemSelected(item);
      }
  
      public class MyClickHandler {
          Context context;
  
          public MyClickHandler(Context context) {
              this.context = context;
          }
   
  
          public void OnAddClicked(View view) {
              //Intent new_intent = new Intent(context, CartList.class);
              Intent new_intent = new Intent(context,CartView.class);
              new_intent.putExtra(&quot;Item&quot;, items);
              new_intent.putExtra(&quot;Quantity&quot;,invoiceDetails.getQuantity());
              new_intent.putExtra(&quot;Price&quot;,invoiceDetails.getUPrice());
              setResult(1, new_intent);
              finish();
  
          }
      }
  }
  </code></pre>