title: How to keep intent for second activity?
body: <p>I have a <code>MainActivity</code> with some cards which have different names. <code>onClick</code>, the title is passed as an <code>intent</code> via the <code>adapter</code> to the <code>secondActivity</code> and displayed as the header. From there, I can go to other activities. If I come back from one of these other activities (via the back button created by establishing second activity as the parent activity) the header is gone. How do I keep the header that was originally passed on as an intent or should I go about this completely different?</p>
  
  <p>I have tried using <code>onResume()</code> and <code>onStart()</code> in the <code>secondActivity</code> to reassign the intent from a global variable.</p>
  
  <p>The <code>adapter</code> class, where the card <code>onClick</code> method is written:</p>
  
  <pre><code>@Override
  public void onBindViewHolder(final TripHolder tripHolder, final int position) {
      Trip trip = trips.get(position);
      tripHolder.setDetails(trip);
  
      tripHolder.itemView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(context, SecondActivity.class);
              TextView card_title = v.findViewById(R.id.TripNamecl);
              intent.putExtra("card_title", card_title.getText().toString());
              context.startActivity(intent);
          }
      });
  }
  </code></pre>
  
  <p>The <code>secondActivity</code> where the header should be displayed:</p>
  
  <pre><code>public class SecondActivity extends AppCompatActivity {
      String name;
      TextView header;
      static final String STATE_HEADER = "header";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_second);
  
          name = getIntent().getStringExtra("card_title");
          header = findViewById(R.id.TripsHeader);
          header.setText(name);
      }
  
      @Override
      public void onSaveInstanceState(Bundle savedInstanceState) {
          super.onSaveInstanceState(savedInstanceState);
          savedInstanceState.putString(STATE_HEADER, name);
      }
  
      @Override
      public void onRestoreInstanceState(Bundle savedInstanceState) {
          super.onRestoreInstanceState(savedInstanceState);
          name = savedInstanceState.getString(STATE_HEADER);
          header.setText(name);
      }
  
      public void launchMapsActivity(View view) {
          Uri gmmIntentUri = Uri.parse("geo:48.8566°,2.3522");
          Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
          mapIntent.setPackage("com.google.android.apps.maps");
          if (mapIntent.resolveActivity(getPackageManager()) != null) {
              startActivity(mapIntent);
          }
      }
  
      public void launchTravelActivity(View view) {
          Intent intent = new Intent(this, TravelActivity.class);
          startActivity(intent);
      }
  
      public void launchPlansActivity(View view) {
          Intent intent = new Intent(this, PlansActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>SOLUTION:
  The solution was to put android:launchMode="singleTop" into the manifest file for the secondactivity. It's described in more detail here: <a href="https://stackoverflow.com/questions/12276027/how-can-i-return-to-a-parent-activity-correctly/15933890#15933890">How can I return to a parent activity correctly?</a></p>