Advertisement
mamamaria

ThirdActivity

Feb 17th, 2022
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package com.example.activslogs;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9.  
  10. public class ThirdActivity extends AppCompatActivity {
  11.  
  12.     @Override
  13.     protected void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.activity_third);
  16.  
  17.         Intent mIntent = getIntent();
  18.         setTitle(mIntent.getStringExtra("in_param")); //если не получится, то вернет null
  19.  
  20.         ((Button) findViewById(R.id.button10)).setOnClickListener(v->{
  21.             Intent intent = new Intent();
  22.             intent.putExtra("param",
  23.                     ((EditText)findViewById(R.id.edInput)).getText().toString());
  24.             setResult(RESULT_OK, intent);
  25.             finish(); //закрывает активность
  26.         });
  27.     }
  28.  
  29.     @Override
  30.     public void onBackPressed() {
  31.         Intent intent = new Intent();
  32.         intent.putExtra("param",
  33.                 ((EditText)findViewById(R.id.edInput)).getText().toString());
  34.         setResult(RESULT_OK, intent);
  35.         super.onBackPressed();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement