title: Application should show prime numbers and start from last shown figure. How to proceed?
body: <p>Would bee glad if someone could help me out with some minor issues.</p>
  
  <p>I want my application to show the user when a prime number has been detected.
  Right now the app only shows the last primenumber depending on the conditons in the while-loop. It would be nice if the primenumber where enumerated every 0.5 second or so.</p>
  
  <p>I tried using thread.sleep but the application does not work normaly. 
  When the app is closed and then restarted, I would like the count to proceed from the last prime number.</p>
  
  <p>Any ides folks?</p>
  
  <pre><code>import android.content.Context;
  import android.content.SharedPreferences;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.TextView;
  import java.lang.Math;
  import java.lang.*;
  import java.util.concurrent.ExecutionException;
  
  public class MainActivity extends AppCompatActivity {
  SharedPreferences sharedPref;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      generateOddNumber(1);
  }
  
  private boolean isPrime(long candidate) {
      long sqrt = (long) Math.sqrt(candidate);
          for (long i = 3; i &lt;= sqrt; i += 2) 
          if (candidate % i == 0) return false;
          return true;
  }
  
  public void saveInfo(long prime) {
      sharedPref = getSharedPreferences("PrimeNumbers", Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedPref.edit();
      editor.putLong("Number", prime);
      editor.apply();
  }
  
  public void getData() {
      sharedPref = getSharedPreferences("PrimeNumbers", Context.MODE_PRIVATE);
      long nr = sharedPref.getLong("Number", 0);
  }
  
  public void generateOddNumber(long x) {
      TextView myTextView = (TextView) findViewById(R.id.textView);
      while (x &lt; 1000) {
          if (isPrime(x) == true) {
              saveInfo(x);
              myTextView.setText(String.valueOf(x));
              try { Thread.sleep(1000);}
              catch (InterruptedException e){
                  e.printStackTrace();
              }
          }
          x = x + 2;
      }
  }
  }
  </code></pre>