title: Adding and Removing Dynamic Buttons From one activity to another activity in android on click of button from previous activity button click
body: <p>I want to develop a similar kind of app(link below)
  <a href="https://stackoverflow.com/questions/15082432/how-to-create-button-dynamically-in-android">How to create Button Dynamically in android?</a>
  But at the same time I want to display this in another activity and not in the same activity.
  there are 2 edit text:
  1) Button Name to be Created.
  2) Destination address (for message to be send on creation of new button).
  whose text is getting passed to another activity for the new button creation.</p>
  
  <p>when I wrote</p>
  
  <pre><code> public void onClick(View v) {    
              // TODO Auto-generated method stub    
          final Context context1=this;    
                 if(v.getId()==R.id.button4){    
       LinearLayout l1 = (LinearLayout) findViewById(R.id.layout);      
    // R.id.layout is the layout id of the xml file for the 2nd activity.    
      Intent intent1 = new Intent(context1,PCode.class);    
      Button b = new Button(this);    
      l1.addView(b);    
      startActivity(intent1);    
  
   }        
  </code></pre>
  
  <p>The activity is not moving to the 2nd activity and the program is terminating. 
  I am able to create new button when doing in the same activity.
  Kindly Help . </p>