title: Resume video where it is left off in android
body: <p>I want to resume a video where it is closed the last time. I have tried it but the problem is that when I close the video the <code>last_position</code> is saved correctly. But when I open that video again, the <code>last_position</code> is 0 meaning that the video opens from the start. How can I take the value of the <code>last_position</code> present in onPause() method and use in onResume() ?</p>
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.MyViewHolder&gt; {
  
  holder.itemView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                Intent intent = new Intent(activity, PlayerActivity.class);
                intent.putExtra(&quot;position&quot;, position);
                activity.startActivity(intent);
           }
     }  
  
  public class  PlayerActivity extends AppCompatActivity{
  SimpleExoPlayer player;
  long last_position;
  PlayerView playerView;
  int position = 0;
  ArrayList&lt;Files&gt; myFiles = new ArrayList&lt;&gt;();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      position = getIntent().getIntExtra(&quot;position&quot;, 0);
      String path = myFiles.get(position).getPath();
      Uri uri = Uri.parse(path);
      player= new SimpleExoPlayer.Builder(this).build();
      DataSource.Factory factory = new DefaultDataSourceFactory
              (this, Util.getUserAgent(this, &quot;My App&quot;));
      ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
  
      MediaSource mediaSource = new ProgressiveMediaSource.Factory(factory, extractorsFactory).createMediaSource(uri);
      playerView.setPlayer(player);
      playerView.setKeepScreenOn(true);
      player.prepare(mediaSource);
  
      if (last_Position &gt; 0){
          simpleExoPlayer.seekTo(last_Position);
      }
  
      player.setPlayWhenReady(true);
  
  @Override
  protected void onPause() {
      super.onPause();
      player.setPlayWhenReady(false);
      player.getPlaybackState();
      if (player != null){
          State.last_Position = (int) player.getCurrentPosition();
          State.click_Position = position;
      }
  }
  
  
  @Override
      protected void onResume() {
        super.onResume();
        if (position != State.click_Position){                
              State.last_Position = 0;
        }
        player.seekTo(State.last_Position);
        player.getPlaybackState();
        player.setPlayWhenReady(true);
   }
  
  
  abstract static class State {
      public static int last_Position = 0;
      public static int click_Position = -1;
      }
    }
  </code></pre>