The best way to start a new activity in Android.
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); myIntent.putExtra("key", value); //Optional parameters CurrentActivity.this.startActivity(myIntent);
The snippet should start the new activity. Note when you set optional parameters you have to add the following code to the onCreate-function in the activity that was started:<code>Intent intent = getIntent(); String value = intent.getStringExtra("key"); //if it's a string you stored.</code> Usually Android Studio and other IDEs add the activity to the manifest-file automatically. If it was not, add <code><activity android:label="@string/app_name" android:name="NextActivity"/></code>
We provide special containers which include the full snippet and a link to this site. So for example when you make a tutorial and you are using code from this site, you can use one of the following snippet embeddings: