Day 06

mail@pastecode.io avatar
unknown
java
5 days ago
4.3 kB
59
Indexable
Never
package sumago.androidipt.day06b2activitylifecycleintent;

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 {

    EditText etEmail;
    Switch switchSubscribe;
    Button btnNext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("mytag","MainActivity=>onCreate()");
        setContentView(R.layout.activity_main);
        etEmail=findViewById(R.id.etEmail);
        switchSubscribe=findViewById(R.id.switchSubscribe);
        btnNext=findViewById(R.id.btnNext);

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


               Intent intent=new Intent(MainActivity.this, SecondActivity.class);
               String email=etEmail.getText().toString();
               intent.putExtra("email",email);
               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 onStop() {
        super.onStop();
        Log.d("mytag","MainActivity=>onStop()");
    }

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

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














////////////////////////////////////////////////////////////////////////////




package sumago.androidipt.day06b2activitylifecycleintent;

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

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;
    TextView tvEmail;

    TextView tvIsSubscribed;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("mytag","SecondActivity=>onCreate()");
        setContentView(R.layout.activity_second);
        btnFinish=findViewById(R.id.btnFinish);
        tvEmail=findViewById(R.id.tvEmail);
        tvIsSubscribed=findViewById(R.id.tvIsSubscribed);

        String email=getIntent().getStringExtra("email");
        boolean isSubscribed=getIntent().getBooleanExtra("isSubscribed",false);
        tvEmail.setText(email);
        tvIsSubscribed.setText(""+isSubscribed);

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

                finish();
            }
        });
    }
    @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 onStop() {
        super.onStop();
        Log.d("mytag","SecondActivity=>onStop()");
    }

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

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