0

How to transfer data from one activity to another and set it to the textview?

This is my intent:

Intent intent=new Intent(v.getContext(),FinalResultActivity.class);
        intent.putExtra("questions_count", questions_count);
        intent.putExtra("questions_correct", questions_correct);
        intent.putExtra("questions_score", questions_score);
        intent.putExtra("questions_correct_list", questions_correct_list);

        v.getContext().startActivity(intent);

I want to pass questions_score to another activity and set it to the textview.

SripadRaj
  • 1,687
  • 2
  • 22
  • 33
Shagun
  • 7
  • 4
  • 1
    Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – Akshay Bhat 'AB' Jul 27 '16 at 06:17
  • Tons of examples are their http://stackoverflow.com/questions/18146614/how-to-send-string-from-one-activity-to-another – Android Surya Jul 27 '16 at 06:20

2 Answers2

0

Try it

class SecondActvty extends activity{

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

        if (getIntent().getExtras() != null ) {
             textView.setText(getIntent().getExtras().getString("questions_count", "")); 
        }
    }

}
V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
Andolasoft Inc
  • 1,296
  • 1
  • 7
  • 16
0

firstActivity

    Intent intent=new Intent(v.getContext(),FinalResultActivity.class);
    intent.putExtra("questions_count", questions_count);
    intent.putExtra("questions_correct", questions_correct);
    intent.putExtra("questions_score", questions_score);
    intent.putExtra("questions_correct_list", questions_correct_list);
    startActivity(intent);
    finish();

FinalResultActivity.class

get value inside the onCreate like

Bundle extras = getIntent().getExtras();
    if (extras != null) {
    String count = extras.getString("questions_count");
    String correct =extras.getString("questions_correct");
        textview.setText(count);
        textview1.setText(correct);
      }
Amit Basliyal
  • 840
  • 1
  • 10
  • 28