0% found this document useful (0 votes)
10 views3 pages

Explicit Intent Example in Android

The document contains code for an Android application with two activities. The main activity contains an edit text for user input and a submit button. When clicked, the button starts a second activity, passing the user input as an extra in the intent. The second activity receives this extra and displays it in a text view on screen.

Uploaded by

Deelip Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Explicit Intent Example in Android

The document contains code for an Android application with two activities. The main activity contains an edit text for user input and a submit button. When clicked, the button starts a second activity, passing the user input as an extra in the intent. The second activity receives this extra and displays it in a text view on screen.

Uploaded by

Deelip Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

activity_main.

xml

<?xml version="1.0" encoding="utf-8"?>


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/txtname"
android:layout_width="287dp"
android:layout_height="55dp"
android:ems="10"
android:hint="Enter Name"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.09" />

<Button
android:id="@+id/btnsubmit"
android:layout_width="156dp"
android:layout_height="53dp"
android:text="Submit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.251" />
</[Link]>

[Link]
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

Button submit=findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
EditText ename=findViewById([Link]);
String name=[Link]().toString();

Intent intent=new Intent([Link],


[Link]);

[Link]("fname",name);
startActivity(intent);
}
});
}
}

[Link]
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">

<TextView
android:id="@+id/textView"
android:layout_width="267dp"
android:layout_height="39dp"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.396"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.167" />
</[Link]>

activity_second.xml
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class SecondActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);
TextView t=findViewById([Link]);

Intent intent=getIntent();
String fname=[Link]("fname");
[Link]("Hello "+fname);
}
}

You might also like