title: Actionbar up navigation with fragment and activity
body: <p>I'm going to use home button (Action bar App icon) as back button. I got it to work but not in the way i intended.</p>
  
  <p>My MainActivity is  an activity which holds (1) a drawer that shows a list of categories. And a Fragment that displays a list of items in the category chosen in the drawer.</p>
  
  <p>when a item in the list is clicked, a new DetailActivity is started to show the details.</p>
  
  <p>here starts the problem:
  From the DetailActivity when i press Back button, it returns to the MainActivity as it was before clicking the item to show details. That is what I expect. However, when use home button as Up navigation, it starts the MainActivity as if I opened the app again. Not showing the list that was previously being shown.</p>
  
  <p>I read in developer documents that for fragments I have to use: .add(detailFragment, "detail") And .addToBackStack() then commit.</p>
  
  <p>But what am I suppose to add in add(---,"---"). And then how should I use it?!</p>
  
  <p>this is my codes:</p>
  
  <p>the method is the MainActivity that shows the content:</p>
  
  <pre><code>    public void refreshDisplay(Context context, View view, String category, int i) {
  
      List&lt;Lesson&gt; lessonByCategory = datasource.findByCategory(category, i);
  
      final ListView lv = (ListView) view.findViewById(R.id.listView);
      final ArrayAdapter&lt;Lesson&gt; adapter = new LessonListAdapter(context, lessonByCategory);
      lv.setAdapter(adapter);
  
  
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          public void onItemClick (AdapterView&lt;?&gt; parent, View view, int position, long id) {
              Log.i(LOGTAG, "onListItemClick called");
  
              ArrayAdapter&lt;Lesson&gt; m_adapter = adapter;
              // get the Lesson object for the clicked row
              Lesson lesson = m_adapter.getItem(position);
  
              Intent intent = new Intent(MainActivity.this, LessonDetailActivity.class);
  
              intent.putExtra(".model.Lesson", lesson);
              intent.putExtra("isStared", isStared);
  
              startActivityForResult(intent, LESSON_DETAIL_ACTIVITY);
  
          }
      });
      }
  </code></pre>
  
  <p>In my LESSON_DETAIL_ACTIVITY that shows the detail content I have this code to enable up navigation for home button:</p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
  
      // I have some other cases here
  
      case android.R.id.home:
          NavUtils.navigateUpFromSameTask(this);
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>And finally in the Manifest I used the code below to introduce MainActivity as the parrent of LessonDetailActivity:</p>
  
  <pre><code>  &lt;activity
          android:name=".LessonDetailActivity"&gt;
          &lt;meta-data
          android:name="android.support.PARENT_ACTIVITY"
          android:value="com.example.MainActivity" /&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>I want the Home button as up navigation to behave like back button so that when its clicked it takes me to the MainActivity as it was before opening the LessonDetailActivity. The code above doesn't do that and every time I press Home in the action bar it starts the MainActivity from scratch.</p>
  
  <p>Could anyone help me with this please?
  I also should say that I'm new so I'd appreciate it if the answers were detailed.</p>