Untitled

mail@pastecode.io avatar
unknown
java
5 days ago
4.7 kB
27
Indexable
Never
package sumago.androidipt.day06b1;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    Button btnNext;
    EditText etEmail;

    Switch switchSubscribe;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("mytag","MainActivity=>onCreate()");
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        btnNext=findViewById(R.id.btnNext);
        etEmail=findViewById(R.id.etEmail);
        switchSubscribe=findViewById(R.id.switchSubscribe);

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

                Intent intent=new Intent(MainActivity.this,SecondActivity.class);
                intent.putExtra("email",etEmail.getText().toString());
                intent.putExtra("isSubscribed",switchSubscribe.isEnabled());
                startActivity(intent);

            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("mytag","MainActivity=>onStart()");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("mytag","MainActivity=>onResume()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("mytag","MainActivity=>onPause()");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("mytag","MainActivity=>onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("mytag","MainActivity=>onDestroy()");
    }
}















//////////////////////////////////////////
package sumago.androidipt.day06b1;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class SecondActivity extends AppCompatActivity {

    Button btnFinish;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("mytag","SecondActivity=>onCreate()");
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_second);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        btnFinish=findViewById(R.id.btnFinish);
        btnFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        String email=getIntent().getStringExtra("email");
        boolean isSubscribed=getIntent().getBooleanExtra("isSubscribed",false);

        Log.d("mytag",email);
        Log.d("mytag",""+isSubscribed);

    }
    @Override
    protected void onStart() {
        super.onStart();
        Log.d("mytag","SecondActivity=>onStart()");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("mytag","SecondActivity=>onResume()");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("mytag","SecondActivity=>onPause()");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("mytag","SecondActivity=>onStop()");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("mytag","SecondActivity=>onDestroy()");
    }
}
Leave a Comment