我想通过保存一个int值来重新创建活动。我不知道为什么onSavedInstance总是具有值null
:
public class ActionActivity extends AppCompatActivity implements View.OnClickListener {
//...
int p = 0;
String newString;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.action);
progress = (TextView) findViewById(R.id.Progress);
if (savedInstanceState != null) {
p = savedInstanceState.getInt("PROGRESS");
}
p++;
newString = String.valueOf(p);
progress.setText(newString);
@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(), ActionActivity.class);
startActivity(i);
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt("PROGRESS", p);
super.onSaveInstanceState(savedInstanceState); }
}