Open new activity

The best way to start a new activity in Android.


Libraries

Code Snippet
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
myIntent.putExtra("key", value); //Optional parameters
CurrentActivity.this.startActivity(myIntent);


Implementation

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>





Comments
  • mode_editWrite a comment



  • forumComments




Embed 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:

Load Preview Get Code Close Preview







    Share
    Rating
    thumb_up 0 thumb_down
    Author
    Thorolus

    I'm the head developer and co-founder of GlovilGames Studios (glovilgames.com) and other platforms GlovilGames created, like vsnippets.com, worth-calculator.net, python-obfuscator.com and some mobile apps and games.

    Tags
    Android
    Basics



    Informations

    posted on 2016-09-24 13:22:06

    viewed 119 times

    snippet's UUID is 57e661de467b7

    Similar Snippets