Value of Toast to TextView of second activity












2















This is my MainActivity.java and I want the results in a text view of another activity? How can I achieve it? Can you Show me with an example please.



public class MainActivity extends AppCompatActivity {
private Button scan_btn;

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

scan_btn=(Button)findViewById(R.id.btnQr);
final Activity activity =this;
scan_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
intentIntegrator.setPrompt("Scan");
intentIntegrator.setCameraId(0);
intentIntegrator.setBeepEnabled(false);
intentIntegrator.setBarcodeImageEnabled(false);
intentIntegrator.initiateScan();

}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null){
if (result.getContents()==null){
Toast.makeText(this,"You cancelled scanning",Toast.LENGTH_LONG).show();

}
else {
Toast.makeText(this,result.getContents(),Toast.LENGTH_LONG).show();
}
}
else {


super.onActivityResult(requestCode, resultCode, data);
}
}
}


This is my Second Activity. Where I want to show the result.



  public class DetailActivity extends AppCompatActivity {
private TextView qrResult;


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

qrResult= findViewById(R.id.qrResult);



}
}


If you want I can post my Layout file as well. Thankyou.










share|improve this question



























    2















    This is my MainActivity.java and I want the results in a text view of another activity? How can I achieve it? Can you Show me with an example please.



    public class MainActivity extends AppCompatActivity {
    private Button scan_btn;

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

    scan_btn=(Button)findViewById(R.id.btnQr);
    final Activity activity =this;
    scan_btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
    intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
    intentIntegrator.setPrompt("Scan");
    intentIntegrator.setCameraId(0);
    intentIntegrator.setBeepEnabled(false);
    intentIntegrator.setBarcodeImageEnabled(false);
    intentIntegrator.initiateScan();

    }
    });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (result != null){
    if (result.getContents()==null){
    Toast.makeText(this,"You cancelled scanning",Toast.LENGTH_LONG).show();

    }
    else {
    Toast.makeText(this,result.getContents(),Toast.LENGTH_LONG).show();
    }
    }
    else {


    super.onActivityResult(requestCode, resultCode, data);
    }
    }
    }


    This is my Second Activity. Where I want to show the result.



      public class DetailActivity extends AppCompatActivity {
    private TextView qrResult;


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

    qrResult= findViewById(R.id.qrResult);



    }
    }


    If you want I can post my Layout file as well. Thankyou.










    share|improve this question

























      2












      2








      2








      This is my MainActivity.java and I want the results in a text view of another activity? How can I achieve it? Can you Show me with an example please.



      public class MainActivity extends AppCompatActivity {
      private Button scan_btn;

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

      scan_btn=(Button)findViewById(R.id.btnQr);
      final Activity activity =this;
      scan_btn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
      intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
      intentIntegrator.setPrompt("Scan");
      intentIntegrator.setCameraId(0);
      intentIntegrator.setBeepEnabled(false);
      intentIntegrator.setBarcodeImageEnabled(false);
      intentIntegrator.initiateScan();

      }
      });
      }

      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
      if (result != null){
      if (result.getContents()==null){
      Toast.makeText(this,"You cancelled scanning",Toast.LENGTH_LONG).show();

      }
      else {
      Toast.makeText(this,result.getContents(),Toast.LENGTH_LONG).show();
      }
      }
      else {


      super.onActivityResult(requestCode, resultCode, data);
      }
      }
      }


      This is my Second Activity. Where I want to show the result.



        public class DetailActivity extends AppCompatActivity {
      private TextView qrResult;


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

      qrResult= findViewById(R.id.qrResult);



      }
      }


      If you want I can post my Layout file as well. Thankyou.










      share|improve this question














      This is my MainActivity.java and I want the results in a text view of another activity? How can I achieve it? Can you Show me with an example please.



      public class MainActivity extends AppCompatActivity {
      private Button scan_btn;

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

      scan_btn=(Button)findViewById(R.id.btnQr);
      final Activity activity =this;
      scan_btn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      IntentIntegrator intentIntegrator = new IntentIntegrator(activity);
      intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
      intentIntegrator.setPrompt("Scan");
      intentIntegrator.setCameraId(0);
      intentIntegrator.setBeepEnabled(false);
      intentIntegrator.setBarcodeImageEnabled(false);
      intentIntegrator.initiateScan();

      }
      });
      }

      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
      if (result != null){
      if (result.getContents()==null){
      Toast.makeText(this,"You cancelled scanning",Toast.LENGTH_LONG).show();

      }
      else {
      Toast.makeText(this,result.getContents(),Toast.LENGTH_LONG).show();
      }
      }
      else {


      super.onActivityResult(requestCode, resultCode, data);
      }
      }
      }


      This is my Second Activity. Where I want to show the result.



        public class DetailActivity extends AppCompatActivity {
      private TextView qrResult;


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

      qrResult= findViewById(R.id.qrResult);



      }
      }


      If you want I can post my Layout file as well. Thankyou.







      java android android-studio android-toast






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '18 at 6:32









      Manish ThapaManish Thapa

      648




      648
























          2 Answers
          2






          active

          oldest

          votes


















          1














          You can put data into the intent from your main acivity and the get the intend from the second activity for the data.
          For example:



          In your MainActivity.class



          Intent intent = new Intent(MainActivity.this, DetailActivity.class);
          intent.putExtra("result", "Your result text here");
          startActivity(intent);


          In Your DetailsActivity.class:



          Intent intent = getIntent();
          String result = intent.getStringExtra("result");
          qrResult.setText(result);


          You can even send any type of object through intent. Please google it for further information.






          share|improve this answer































            2














            You need to create a new Intent object, and add it extra data with intent.putextra(). This method can take a String object as an argument. You need to specify a unique key for that string.Then start the new activity. For example
            Intent i = new Intent(context, nextactivity.class)
            i.putextra(“stringKey”,yourSstring)
            startActivity(i)



            Then, in the second activity, you need to get the intent that started that activity (with getIntent), you can use it as early as onCreate.
            The getIntent function returns the intent object that started the new activity.
            When you have the new intent, you can get the extra string you passed from the old activity, with intent.getStringExtra(“stringKey”)
            This allows you to pass simple data between activities. Make sure to use the same key.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465222%2fvalue-of-toast-to-textview-of-second-activity%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You can put data into the intent from your main acivity and the get the intend from the second activity for the data.
              For example:



              In your MainActivity.class



              Intent intent = new Intent(MainActivity.this, DetailActivity.class);
              intent.putExtra("result", "Your result text here");
              startActivity(intent);


              In Your DetailsActivity.class:



              Intent intent = getIntent();
              String result = intent.getStringExtra("result");
              qrResult.setText(result);


              You can even send any type of object through intent. Please google it for further information.






              share|improve this answer




























                1














                You can put data into the intent from your main acivity and the get the intend from the second activity for the data.
                For example:



                In your MainActivity.class



                Intent intent = new Intent(MainActivity.this, DetailActivity.class);
                intent.putExtra("result", "Your result text here");
                startActivity(intent);


                In Your DetailsActivity.class:



                Intent intent = getIntent();
                String result = intent.getStringExtra("result");
                qrResult.setText(result);


                You can even send any type of object through intent. Please google it for further information.






                share|improve this answer


























                  1












                  1








                  1







                  You can put data into the intent from your main acivity and the get the intend from the second activity for the data.
                  For example:



                  In your MainActivity.class



                  Intent intent = new Intent(MainActivity.this, DetailActivity.class);
                  intent.putExtra("result", "Your result text here");
                  startActivity(intent);


                  In Your DetailsActivity.class:



                  Intent intent = getIntent();
                  String result = intent.getStringExtra("result");
                  qrResult.setText(result);


                  You can even send any type of object through intent. Please google it for further information.






                  share|improve this answer













                  You can put data into the intent from your main acivity and the get the intend from the second activity for the data.
                  For example:



                  In your MainActivity.class



                  Intent intent = new Intent(MainActivity.this, DetailActivity.class);
                  intent.putExtra("result", "Your result text here");
                  startActivity(intent);


                  In Your DetailsActivity.class:



                  Intent intent = getIntent();
                  String result = intent.getStringExtra("result");
                  qrResult.setText(result);


                  You can even send any type of object through intent. Please google it for further information.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 '18 at 7:13









                  Gourango SutradharGourango Sutradhar

                  2468




                  2468

























                      2














                      You need to create a new Intent object, and add it extra data with intent.putextra(). This method can take a String object as an argument. You need to specify a unique key for that string.Then start the new activity. For example
                      Intent i = new Intent(context, nextactivity.class)
                      i.putextra(“stringKey”,yourSstring)
                      startActivity(i)



                      Then, in the second activity, you need to get the intent that started that activity (with getIntent), you can use it as early as onCreate.
                      The getIntent function returns the intent object that started the new activity.
                      When you have the new intent, you can get the extra string you passed from the old activity, with intent.getStringExtra(“stringKey”)
                      This allows you to pass simple data between activities. Make sure to use the same key.






                      share|improve this answer




























                        2














                        You need to create a new Intent object, and add it extra data with intent.putextra(). This method can take a String object as an argument. You need to specify a unique key for that string.Then start the new activity. For example
                        Intent i = new Intent(context, nextactivity.class)
                        i.putextra(“stringKey”,yourSstring)
                        startActivity(i)



                        Then, in the second activity, you need to get the intent that started that activity (with getIntent), you can use it as early as onCreate.
                        The getIntent function returns the intent object that started the new activity.
                        When you have the new intent, you can get the extra string you passed from the old activity, with intent.getStringExtra(“stringKey”)
                        This allows you to pass simple data between activities. Make sure to use the same key.






                        share|improve this answer


























                          2












                          2








                          2







                          You need to create a new Intent object, and add it extra data with intent.putextra(). This method can take a String object as an argument. You need to specify a unique key for that string.Then start the new activity. For example
                          Intent i = new Intent(context, nextactivity.class)
                          i.putextra(“stringKey”,yourSstring)
                          startActivity(i)



                          Then, in the second activity, you need to get the intent that started that activity (with getIntent), you can use it as early as onCreate.
                          The getIntent function returns the intent object that started the new activity.
                          When you have the new intent, you can get the extra string you passed from the old activity, with intent.getStringExtra(“stringKey”)
                          This allows you to pass simple data between activities. Make sure to use the same key.






                          share|improve this answer













                          You need to create a new Intent object, and add it extra data with intent.putextra(). This method can take a String object as an argument. You need to specify a unique key for that string.Then start the new activity. For example
                          Intent i = new Intent(context, nextactivity.class)
                          i.putextra(“stringKey”,yourSstring)
                          startActivity(i)



                          Then, in the second activity, you need to get the intent that started that activity (with getIntent), you can use it as early as onCreate.
                          The getIntent function returns the intent object that started the new activity.
                          When you have the new intent, you can get the extra string you passed from the old activity, with intent.getStringExtra(“stringKey”)
                          This allows you to pass simple data between activities. Make sure to use the same key.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 25 '18 at 7:09









                          Daniel B.Daniel B.

                          1,156111




                          1,156111






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465222%2fvalue-of-toast-to-textview-of-second-activity%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown