I generate a random number when I open the application and I save this number with Sharedpreferences. This is my code:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random r = new Random();
int number = r.nextInt(100);
SharedPreferences randomnumber = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = randomnumber.edit();
editor.putInt("intValue",number);
editor.commit();
}
}
Can I collect old and new numbers when I open the application?