title: Why ViewModel is not providing data when I return to activity?
body: <p><strong>MainActivity</strong> uses <strong>ViewModel</strong> to display a list of books. When I return back from <strong>DetailActivity</strong> to  <strong>MainActivity</strong>. <strong>MainActivity</strong> does not have the list anymore.</p>
  
  <p><strong>Why ViewModel is not providing the list when I return to MainActivity?</strong> </p>
  
  <p><strong>How can I retain the list for MainActivity?</strong></p>
  
  <p>MainActivity shows a list of books. When user touch list item. It starts <strong>BookDetailActivity</strong> by using below method.</p>
  
  <pre class="lang-java prettyprint-override"><code>private void startDetailActivity(String id){
  
          Intent detailActivity = new Intent(this,BookDetailActivity.class);
          detailActivity.putExtra("id",id);
          startActivity(detailActivity);
  
      }
  </code></pre>
  
  <p>It uses <strong>ViewModel</strong> to get and display book list. <strong>ViewModel</strong> is initialized by this method.</p>
  
  <pre class="lang-java prettyprint-override"><code>    @Override
      protected void onResume(){
          super.onResume();
  
          bookViewModel = ViewModelProviders.of(this).get(BookViewModel.class);
  
          //book list live data observer
          bookViewModel.getBookList().observe(this, new Observer&lt;ArrayList&lt;Book&gt;&gt;() {
              @Override
              public void onChanged(@Nullable ArrayList&lt;Book&gt; books) {
                  Log.i("Adapter",""+books.size());
                  adapter.clear();
                  adapter.setData(books);
                  adapter.notifyDataSetChanged();
                  progressBar.setVisibility(View.GONE);
              }
          });
  
  
          //status live data observer
          bookViewModel.getStatus().observe(this, new Observer&lt;Boolean&gt;() {
              @Override
              public void onChanged(@Nullable Boolean aBoolean) {
                  showErrorMessage();
              }
          });
  
      }
  </code></pre>
  
  <p><strong>BookDetailActivity</strong></p>
  
  <p>This activity load book detail from data. It also uses the same <strong>ViewModel</strong> to get and display data. The <strong>ViewModel</strong> is initialized in the <strong>onCreate() method</strong> of <strong>BookDetailActivity</strong>. </p>
  
  <pre class="lang-java prettyprint-override"><code> @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_book_detail);
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          Intent data = getIntent();
  
          String id = data.getStringExtra("id");
  
          viewModel = ViewModelProviders.of(this).get(BookViewModel.class);
  
          //book detail observer
          viewModel.getBookDetail().observe(this, new Observer&lt;BookDetail&gt;() {
              @Override
              public void onChanged(@Nullable BookDetail bookDetail) {
                  setDetail(bookDetail);
              }
          });//end of observer
  
          viewModel.getBookDetail(id);
      }
  </code></pre>
  
  <p>In <strong>Manifest</strong> file, <strong>BookDetailActivity</strong> has <strong>MainActivity</strong> as its parent activity. User can go back to the <strong>MainActivity</strong> by pressing the back button in the top left corner.</p>
  
  <p><strong>BookViewModel</strong></p>
  
  <p><strong>BookViewModel</strong> extends <strong>ViewModel</strong> class. It has three <strong>LiveData objects</strong> for the <strong>book, book detail, and status</strong>. <strong>Book LiveData</strong> is observed by <strong>MainActivity</strong>. It returns a list of book. <strong>Book detail LiveData</strong> is observed by <strong>BookDetailActivity</strong>.  It returns a BookDetail object. Status is observed by both  Activities for network request status.  </p>
  
  <pre class="lang-java prettyprint-override"><code>package com.google.firebase.udacity.findabook.viewmodel;
  
  import android.app.Application;
  import android.arch.lifecycle.AndroidViewModel;
  import android.arch.lifecycle.LiveData;
  import android.arch.lifecycle.ViewModel;
  import android.util.Log;
  
  import com.google.firebase.udacity.findabook.model.BookDetail;
  import com.google.firebase.udacity.findabook.repository.BookRepository;
  import com.google.firebase.udacity.findabook.model.Book;
  
  import java.util.ArrayList;
  
  public class BookViewModel extends ViewModel {
      private LiveData&lt;ArrayList&lt;Book&gt;&gt; bookList;
      private LiveData&lt;Boolean&gt; status;
      private LiveData&lt;BookDetail&gt; bookDetail;
      private BookRepository repository;
  
      public BookViewModel(){
          repository = new BookRepository();
          bookList = repository.getBookList();
          status = repository.getStatus();
          bookDetail = repository.getBookDetail();
      }
  
      public LiveData&lt;ArrayList&lt;Book&gt;&gt; getBookList(){ return bookList;}
  
      public LiveData&lt;Boolean&gt; getStatus(){return status;}
  
      public LiveData&lt;BookDetail&gt; getBookDetail(){return bookDetail;}
  
      public void searchByBookName(String bookName){
          repository.makeRequestBasedOnBookName(bookName);
      }
  
      public void getBookDetail(String id){
          repository.getBookDetail(id);
      }
  
      @Override
      protected void onCleared() {
          super.onCleared();
          Log.i("Book view model","Cleared");
      }
  }
  </code></pre>
  
  <p><strong>I have tried--</strong></p>
  
  <p><strong>-> Moving the initialization of view model from resume to start method.</strong> </p>
  
  <p><strong>-> extended viewmodel from AndroidViewModel class</strong></p>