Demo entry 6657828

sdfgfdsg

   

Submitted by anonymous on Nov 04, 2017 at 23:13
Language: Java. Code size: 2.0 kB.

package com.example.ssame.intent;

  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;

  public class MainActivity extends AppCompatActivity {

      private static final int SECOND_ACTIVITY_RESULT_CODE = 1;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Button button = (Button) findViewById(R.id.first);
          button.setOnClickListener(new View.OnClickListener() {
         @Override
          public void onClick(View view) {
               onButtonClick(view);
                                        }
                                    }
          );
      }

      // "Go to Second Activity" button click
      public void onButtonClick(View view) {

          // Start the SecondActivity
          Intent intent = new Intent(this, SecondActivity.class);
          startActivityForResult(intent, SECOND_ACTIVITY_RESULT_CODE);
      }

      // This method is called when the second activity finishes
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);

          // check that it is the SecondActivity with an OK result
          if (requestCode == SECOND_ACTIVITY_RESULT_CODE) {
              if (resultCode == RESULT_OK) {

                  // get String data from Intent
                  String returnString = data.getStringExtra(Intent.EXTRA_TEXT);

                  // set text view with string
                  TextView textView = (TextView) findViewById(R.id.text);
                  textView.setText(returnString);

//                textview.setText(data.getData().toString());
                  }
              }
  }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).