+ Reply to Thread
Results 1 to 2 of 2

Thread: how to start a new activity when click on button

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    14

    how to start a new activity when click on button

    in android application , how to start a new activity (GUI) when click on a button on another activity , and how to pass data between these two activities ??

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    13
    Code:
    Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
    CurrentActivity.this.startActivity(myIntent);
    To pass info just use extras:
    Code:
    myIntent.putExtra("key", value);
    This can be retrieved on the other side via

    [code edited]
    Code:
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    String value = intent.getStringExtra("key"); //if it's a string you stored.
    Don't forget to add your new activity in the AndroidManifest.xml:
    Code:
    <activity android:label="@string/app_name" android:name="NextActivity"/>

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts