package com.example.patrice.preferences;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

//https://www.javatpoint.com/android-startactivityforresult-example

public class activity_for_result extends Activity
{
    TextView textView1;
    Button button1;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_for_result_view);

        textView1=(TextView)findViewById(R.id.textView1);
        button1=(Button)findViewById(R.id.button1);

        button1.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View arg0)
            {
                Intent intent=new Intent(activity_for_result.this, reponse_activity_for_result .class);
                startActivityForResult(intent, 2);// Activity is started with requestCode 2
            }
        });
    }

    // Call Back method  to get the Message form other Activity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        // check if the request code is same as what is passed  here it is 2
        if(requestCode==2)
        {
            String message=data.getStringExtra("MESSAGE");
            textView1.setText(message);
        }
    }

}