title: How to get Switch value from one Activity and display it in other activity
body: <p>I am a beginner in Android application development. I'm just trying to get Switch value from one Activity and display it in another activity. But I am getting 'null' as output. Please help me.</p>
  
  <p><b>Question1.java</b></p>
  
  <pre><code>public class Question1Activity extends AppCompatActivity {
  Switch swi;
  Button back1, next1;
  String value = "NO";
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_question1);
      swi = (Switch) findViewById(R.id.Switch_Ques_1);
      back1 = (Button) findViewById(R.id.Button_back1);
      next1 = (Button) findViewById(R.id.Button_next1);
      swi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView,
                                       boolean isChecked) {
  
              if (isChecked) {
                  swi.setText("YES");
                  value="YES";
                  swi.setTextColor(Color.GREEN);
              } else {
                  swi.setText("NO");
                  value="NO";
                  swi.setTextColor(Color.RED);
              }
  
          }
      });
      back1.setOnClickListener(new View.OnClickListener(){
          public void onClick(View view){
              Intent intent = new Intent(Question1Activity.this,LoginActivity.class);
              startActivity(intent);
          }
      });
      next1.setOnClickListener(new View.OnClickListener(){
          public void onClick(View view){
              Intent intent = new Intent(Question1Activity.this,Question2Activity.class);
              intent.putExtra("Ans1",swi.isChecked());
              startActivity(intent);
          }
      });
  }
  }
  </code></pre>
  
  <p><b>Question3.java</b></p>
  
  <pre><code>public class Question3Activity extends AppCompatActivity {
  TextView t1;
  private SQLiteDatabase database;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_question3);
      t1 = (TextView) findViewById(R.id.result);
      Intent intent = getIntent();
      String s1 =(String) intent.getStringExtra("Ans1");
      String s2 = intent.getStringExtra("Ans2");
      t1.setText(s1+" "+s2);
  }
  }
  </code></pre>