Tuesday, November 1, 2022

PROGRAM 05 : AIM: - To understand Activity , Intent

 Code:-

XML Code:

 

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:background="@drawable/prog3"
   
tools:context=".MainActivity">


    <
Button
       
android:id="@+id/button"
       
android:layout_width="135dp"
       
android:layout_height="77dp"
       
android:text="Button"
       
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.354" />


</
androidx.constraintlayout.widget.ConstraintLayout>

 

activity_login.xml
 
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:background="@drawable/dd"
   
tools:context=".LoginActivity">


    <
Button
       
android:id="@+id/button2"
       
android:layout_width="176dp"
       
android:layout_height="57dp"
       
android:text="Button"
       
app:layout_constraintBottom_toBottomOf="parent"
       
app:layout_constraintEnd_toEndOf="parent"
       
app:layout_constraintStart_toStartOf="parent"
       
app:layout_constraintTop_toTopOf="parent" />
</
androidx.constraintlayout.widget.ConstraintLayout>

 

JavaCode :

Main Activity :

package com.example.mansamcapro5;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
   
Button btlogin;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(
R.layout.activity_main);

       
btlogin = (Button) findViewById(R.id.button);

       
btlogin.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {

               
Intent intent = new Intent(getApplicationContext(),LoginActivity.class);
                startActivity(
intent);

            }
        });


    }

}

Login Activity:

 

package com.example.mansamcapro5;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class LoginActivity extends AppCompatActivity {
   
Button btnlog;


   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(
R.layout.activity_login);

       
btnlog = (Button) findViewById(R.id.button2);

       
btnlog.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {

               
Intent intent = new Intent(getApplicationContext(),MainActivity.class);

                startActivity(
intent);

            }
        });

    }
}

Output:






 

No comments:

Post a Comment

PROGRAM 05 : AIM: - To understand Activity , Intent

  Code:- XML Code:   Activity_main.xml <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constrain...