Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You create your Intent to your new Activity, add any extras, and start the activity through a context:</p> <pre><code>Intent i = new Intent(context, MyOtherActivity.class); //Initialize the Intent i.putExtra("firstExtra", value); //Put any extra you want i.putExtra("secondExtra", secondValue); //Remember the key you used context.startActivity(i); //Start the activity with the given intent </code></pre> <p>You can put this inside your button's onClick event:</p> <pre><code>public void goToOtherActivity(View view) { //CODE HERE } </code></pre> <p>And define the button in xml like this:</p> <pre><code>&lt;Button android:id="@+id/btnGo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="goToOtherActivity" /&gt; </code></pre> <p>Then in the other Activity you can grab the extras and use them to do whatever you want:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { Intent i = getIntent(); //Get the intent used to run this Activity Bundle b = i.getExtras(); //Get all the extras String firstExtra = b.getString("firstExtra"); //Get one String extra with key "firstExtra" int secondExtra = b.getInt("secondExtra"); //Get one Integer extra with key "secondExtra" //USE YOUR DATA } </code></pre> <p>EDIT:</p> <p>When I said put the code inside that method I meant to do something like this:</p> <pre><code>public class MyActivity extends Activity{ @Override public void onCreate() { super.onCreate(); //onCreate code here } public void goToOtherActivity(View view) { Intent i = new Intent(this, SecondActivity.class); this.startActivity(i); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload