Android Club – Go to another activity using Intent

ActivityA.java

public class ActivityA extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_a);

        // find button
        Button bOpenActivityB = (Button) findViewById(R.id.bOpenActivityB);
        // set on click listener
        // when you click this button, slushatel's code will work
        bOpenActivityB.setOnClickListener(slushatel);

    }

    View.OnClickListener slushatel = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // create intent
            // go from ActivityA to ActvityB
            Intent sel = new Intent(ActivityA.this, ActivityB.class);
            // let's go
            startActivity(sel);
        }
    };

}

activity_a.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   tools:context="net.joerichard.helloandroid.ActivityA">

    <Button
       android:id="@+id/bOpenActivityB"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Сим сим откройся"/>

</LinearLayout>

ActivityB.java

public class ActivityB extends ActionBarActivity {

    static int create_counter = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_b);

    }

}