0% found this document useful (0 votes)
5 views4 pages

Android Intent Example Code

smart device lab intent program

Uploaded by

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

Android Intent Example Code

smart device lab intent program

Uploaded by

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

Intent example

[Link]
package [Link];

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

import [Link];

public class MainActivity extends AppCompatActivity {

EditText etName;
Button btnSend;

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

etName = findViewById([Link]);
btnSend = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
String name = [Link]().toString();
Intent intent = new Intent([Link], [Link]);
[Link]("USERNAME", name);
startActivity(intent);
}
});
}
}

[Link]
package [Link];

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

import [Link];

public class SecondActivity extends AppCompatActivity {

TextView tvResult;

@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_second);

tvResult = findViewById([Link]);
String receivedName = getIntent().getStringExtra("USERNAME");
[Link]("Hello " + receivedName);
}
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="@string/enter_your_name"/>

<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/send_data"/>
</LinearLayout>

activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"/>
</LinearLayout>

You might also like