how to start the second activity from the first, directly, not through a button : All the textbooks/guides start the second activity via click a button.

I thought I can start it directly by just removing the button codes.
Obvious I was wrong. Below code reports "Unfortunately, the xxxx has stopped".

So, my question: ow to start the second activity from the first?

(I can't believe I am the only newbies need to seek help on this while others figured it out by themselves for I can not google the similar question)

Thanks.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent iCodes = new Intent(this, OtherActivity.class);
        startActivity(iCodes);

    }