How to recive data from multiple Activities in Android?Stop Unexpectedly
<p>I am developing sample a android app having three activities named Stationary, Books and Pens. I want to send data from Books and Pens activities to Stationary activity. In Stationary activity when I receive data from one activity either Books or Pens it works fine but when I receive data from both the activities my app "Stop Unexpectedly"</p>

<p>I have developed some code in this respect you can check it below.</p>

<p>in my Book activity am using the following code.</p>

<pre><code>    // in Book Activity
public boolean onKeyDown(int keyCode, KeyEvent event) 
     {
         if ((keyCode == KeyEvent.KEYCODE_BACK))
         {  



                if(myBookSelected)
                {   
                Intent intent = new Intent(Books.this,Stationary.class);
                intent.putExtra("bookSelected", books.toString());
                startActivity(intent);
                }

                else
                {
                    Toast.makeText(getApplicationContext(), "Please select books", Toast.LENGTH_LONG).show();
                }

          }

         return true;
     }
</code></pre>

<p>and in my Pens Activity am using the flowing code.</p>

<pre><code>// in Pen Activity
public boolean onKeyDown(int keyCode, KeyEvent event) 
     {
         if ((keyCode == KeyEvent.KEYCODE_BACK))
         {  



                if(myPenSelected)
                {   
                Intent intent = new Intent(Pens.this,Stationary.class);
                intent.putExtra("penSelected", pens.toString());
                startActivity(intent);
                }

                else
                {
                    Toast.makeText(getApplicationContext(), "Please select Pens", Toast.LENGTH_LONG).show();
                }

          }

         return true;
     }
</code></pre>

<p>To receive data in Stationary activity from the above two activities that is Books and Pens. I am using the following code.</p>

<pre><code>// in Stationary Activity
Bundle extras = getIntent().getExtras();


            if (extras != null)
            {   
                numberOfBooks = extras.getString("bookSelected");
                numberOfPens = extras.getString("penSelected");
            }
</code></pre>

<p>NOTE: When I receive data from one activity either Books or Pens it works fine but when I receive data from both the activities my app "Stop Unexpectedly" </p>
