package com.example.firstmultiscreen;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText editText;
public static final String EXTRA_NAME = "com.example.firstmultiscreen.extra.NAME";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void openActivity(View v){
Toast.makeText(this, "Openning Second Activity", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this , MainActivity2.class);
editText = findViewById(R.id.name);
String nameTest = editText.getText().toString();
intent.putExtra(EXTRA_NAME, nameTest);
startActivity(intent);
}
}
Second page Activity
package com.example.firstmultiscreen;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity2 extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
textView = findViewById(R.id.textView);
Intent intent = getIntent();
String name = intent.getStringExtra(MainActivity.EXTRA_NAME);
textView.setText("Your Name is :" + name);
}
}
Comments
Post a Comment