// SimpleIntentsActivity.java (c) Kari Laitinen // http://www.naturalprogramming.com // 2012-10-11 File created. // 2015-03-16 Latest modification. /* This programs shows: - how to use an Intent to start another activity - how to construct a UI without XML layout To run this program in Android Studio, create a project with SimpleIntentsActivity as its main class, and use the package name below. Then you have to copy this file and the file RedSquareActivity.java to the appropriate folder in the project. Then you have to modify the AndoidManifest.xml of the project as described at the end of this file. */ package simple.intents ; import android.app.Activity; import android.os.Bundle; import android.view.View ; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ScrollView; import android.widget.TextView; import android.content.Intent ; public class SimpleIntentsActivity extends Activity { public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ) ; ScrollView scroll_view = new ScrollView( this ) ; LinearLayout linear_layout = new LinearLayout( this ) ; linear_layout.setOrientation( LinearLayout.VERTICAL ) ; scroll_view.addView( linear_layout ); TextView textview = new TextView( this ) ; textview.setText( "This is SimpleIntentsActivity" ) ; linear_layout.addView( textview ) ; Button button = new Button( this ) ; button.setText( "Click this button!" ) ; button.setOnClickListener( new View.OnClickListener() { public void onClick( View view ) { Intent intent=new Intent( SimpleIntentsActivity.this, RedSquareActivity.class ) ; startActivity( intent ) ; } }); linear_layout.addView( button ) ; this.setContentView( scroll_view ) ; } } /****** NOTES: On 2015-03-16 I was able to run this app after I copied the following to AndroidManifest.xml http://mobileorchard.com/android-app-development-using-intents-to-pass-data-and-return-results-between-activities/ The following AndroidManifest.xml was used earlier. *****/