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

Experiment No 19: Activity Main

The document outlines the XML layout and Java code for two Android activities: MainActivity and SecondActivity. MainActivity includes buttons for opening a dialer and navigating to a second activity, while SecondActivity displays a welcome message with the user's name passed from MainActivity. The code demonstrates the use of implicit and explicit intents for navigation and data transfer between activities.

Uploaded by

ayushx312
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

Experiment No 19: Activity Main

The document outlines the XML layout and Java code for two Android activities: MainActivity and SecondActivity. MainActivity includes buttons for opening a dialer and navigating to a second activity, while SecondActivity displays a welcome message with the user's name passed from MainActivity. The code demonstrates the use of implicit and explicit intents for navigation and data transfer between activities.

Uploaded by

ayushx312
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

Experiment no 19

Activity main:
<?xml version="1.0" encoding="utf-8"?> android:layout_height="wrap_content"
<LinearLayout android:text="Open Google Website"
xmlns:android="[Link] android:layout_marginTop="15dp"/>
m/apk/res/android"
android:layout_width="match_parent" <Button
android:layout_height="match_parent" android:id="@+id/btnDial"
android:orientation="vertical"
android:padding="20dp" android:layout_width="match_parent"
android:gravity="center">
android:layout_height="wrap_content"
<EditText android:text="Open Dialer"
android:id="@+id/editTextName" android:layout_marginTop="10dp"/>

android:layout_width="match_parent" <Button
android:id="@+id/btnNext"
android:layout_height="wrap_content"
android:hint="Enter your name"/> android:layout_width="match_parent"

<Button android:layout_height="wrap_content"
android:id="@+id/btnWebsite" android:text="Go To Second Activity"
android:layout_marginTop="10dp"/>
android:layout_width="match_parent"
</LinearLayout>

Activity second:
<?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/textResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="Welcome"/>

</LinearLayout>
MainActivity:
package [Link];
[Link]([Link]("[Link]
import [Link]"));
[Link] startActivity(intent);
y;
import [Link]; });
import [Link].*;
import [Link]; // Implicit Intent - Open Dialer
import [Link]; [Link](v -> {

public class MainActivity extends Intent intent = new


AppCompatActivity { Intent(Intent.ACTION_DIAL);

EditText name; [Link]([Link]("[Link]


Button btnWebsite, btnDial, btnNext; ;
startActivity(intent);
@Override
protected void onCreate(Bundle });
savedInstanceState) {
[Link](savedInstanceState); // Explicit Intent + Passing Data
[Link](v -> {
setContentView([Link].activity_main);
String username =
name = [Link]().toString();
findViewById([Link]);
btnWebsite = Intent intent = new
findViewById([Link]); Intent([Link],
btnDial = findViewById([Link]); [Link]);
btnNext = findViewById([Link]); [Link]("USERNAME",
username);
// Implicit Intent - Open Website startActivity(intent);
[Link](v -> {
});
Intent intent = new }
Intent(Intent.ACTION_VIEW); }

[Link]
package [Link]; @Override
import protected void onCreate(Bundle
[Link] savedInstanceState) {
y; [Link](savedInstanceState);
import [Link];
import [Link]; setContentView([Link].activity_second);
import [Link]; textResult =
public class SecondActivity extends findViewById([Link]);
AppCompatActivity { Intent intent = getIntent();
TextView textResult; String name =
[Link]("USERNAME"); }
}
[Link]("Hello " + name);

You might also like