MainActivity.java
package first.learn.listviewproject;
import static first.learn.listviewproject.MainActivity2.Message;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button btnOne, btnTwo;
TextView tvOne;
/*
Activity Starting :
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Screen One ");
btnOne = (Button)findViewById(R.id.btnOne);
tvOne = (TextView)findViewById(R.id.tvOne);
btnTwo = (Button)findViewById(R.id.btnTwo);
btnOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MainActivity2.class));
}
});
btnTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Alert ")
.setMessage("yes ")
.setPositiveButton("Ok", null)
.create().show();
}
});
System.out.println("Calling Method : Oncreate - Activity 1");
}@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
System.out.println("Calling Method : onWindowFocusChanged - Activity 1");
}
@Override
protected void onStart() {
super.onStart();
System.out.println("Calling Method : OnStart - Activity 1");
}
@Override
protected void onResume() {
super.onResume();
System.out.println("Calling Method : OnResume - Activity 1 ");
tvOne.setText(Message);
}
/*
Activity Closing :
*/
@Override
protected void onPause() {
super.onPause();
System.out.println("Calling Method : onPause - Activity 1");
}
@Override
protected void onStop() {
super.onStop();
System.out.println("Calling Method : onStop - Activity 1");
}
@Override
protected void onDestroy() {
super.onDestroy();
System.out.println("Calling Method : onDestroy - Activity 1");
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="16dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnOne"
android:text="Next Activity 2"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnTwo"
android:text="Show Alert"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:id="@+id/tvOne"
/>
</LinearLayout>
ActivityMain2.Java
package first.learn.listviewproject;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.EditText;
public class MainActivity2 extends AppCompatActivity {
public static String Message = "";
EditText etOne;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
setTitle("Screen 2");
etOne = (EditText)findViewById(R.id.etOne);
System.out.println("Calling Method : OnCreate - Activity 2");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
System.out.println("Calling Method : Post Delayed - Activity 2");
}
},500);
}
@Override
protected void onStart() {
super.onStart();
System.out.println("Calling Method : OnStart - Activity 2");
}
@Override
protected void onResume() {
super.onResume();
System.out.println("Calling Method : OnResume - Activity 2");
}
/*
Activity Closing :
*/
@Override
protected void onPause() {
super.onPause();
System.out.println("Calling Method : onPause - Activity 2");
}
@Override
protected void onStop() {
super.onStop();
System.out.println("Calling Method : onStop - Activity 2");
}
@Override
protected void onDestroy() {
super.onDestroy();
System.out.println("Calling Method : onDestroy - Activity 2");
}
@Override
public void onBackPressed() {
String s = etOne.getText().toString();
Message = s ;
super.onBackPressed();
}
}
Activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".MainActivity2"
android:orientation="vertical"
android:layout_margin="16dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etOne"
android:hint="Write"
android:inputType="number"/>
</LinearLayout>
No comments:
Post a Comment