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

Explicit Intent Implementation

The document outlines the implementation of an Android application with two activities: MainActivity and Logout. It provides XML layouts for both activities and their corresponding Java classes, detailing how to navigate between them using explicit intents. Additionally, it includes the necessary declarations in the AndroidManifest.xml file to register the activities.

Uploaded by

lastmyko164
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)
5 views3 pages

Explicit Intent Implementation

The document outlines the implementation of an Android application with two activities: MainActivity and Logout. It provides XML layouts for both activities and their corresponding Java classes, detailing how to navigate between them using explicit intents. Additionally, it includes the necessary declarations in the AndroidManifest.xml file to register the activities.

Uploaded by

lastmyko164
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

Explicit Intent Implementation (Lab Practice)

1) Create the first Activity Layout(activity_main.xml)


<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World! This is the first Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.464"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.2" />

<Button
android:id="@+id/btnc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to go the Second Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

2) Create the first Activity Java class ([Link])


package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private Button btn1;
@Override
protected void onCreate(Bundle k) {
[Link](k);
[Link](this);
setContentView([Link].activity_main);
[Link](findViewById([Link]), (v,
insets) -> {
Insets systemBars =
[Link]([Link]());
[Link]([Link], [Link],
[Link], [Link]);
return insets;
});
btn1=findViewById([Link]);
[Link](view -> {
Intent i=new Intent([Link],[Link]);
startActivity(i);
});
}}

3) Create the Second Activity Layout(activity_logout.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">
<Button
android:id="@+id/btngo"
android:layout_width="193dp"
android:layout_height="133dp"
android:text="Go to back"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/imageView"
android:layout_width="238dp"
android:layout_height="168dp"
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.111"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
</[Link]>
4) Create the Second Activity Java class ([Link])
package [Link];

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

import [Link];
public class Logout extends AppCompatActivity {
private Button btn2;
@Override
protected void onCreate(Bundle k) {
[Link](k);
setContentView([Link].activity_logout);
[Link](getApplicationContext(),"This is the second
Activity",Toast.LENGTH_LONG).show();
btn2=findViewById([Link]);
[Link](v->{
Intent a2=new Intent([Link],[Link]);
startActivity(a2);
});
}}
5) Declare all activities in [Link] file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
xmlns:tools="[Link]

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]">

<activity android:name=".Logout" />


<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />

<category android:name="[Link]" />


</intent-filter>
</activity>
</application>

</manifest>

You might also like