I have two activities, Activity A, and B. When user clicks on a topicTextView in the Activity A, it takes him to Activity B where user choses a Topic and pass selectedTopic to the Activity A.
I have implemented the following but app crashes first time when opens Activity A.
Activity A
@Override
protected void onCreate(Bundle savedInstanceState) {
  topicTextView = (TextView) findViewById(R.id.topicTextView);
  // crashes in the following line
  String selectedTopic = getIntent().getExtras().getString("selectedTopic");
  if (selectedTopic != null && !selectedTopic.isEmpty()) {
   topicTextView.setText(selectedTopic);
  }
}
Activity B
@Override
 protected void onCreate(Bundle savedInstanceState) {
   listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)   {
      Intent i = new Intent(ActivityB.this, ActivityA.class);
      i.putExtra("selectedTopic", topics[position].toString());
      startActivity(i);
   }
 });
}
 
     
     
     
    