Passing Extras and screen rotation

ⅰ亾dé卋堺 提交于 2019-12-02 11:51:53
Gaurang Agarwal

Try this code to store the values for the activity

Long value;

protected void onSaveInstanceState(Bundle onOrientChange) {
    super.onSaveInstanceState(onOrientChange);
    onOrientChange.putLong("myValue", value);  
}

And restore the values in onCreate():

public void onCreate(Bundle onOrientChange) {
  if (onOrientChange!= null){
   value = onOrientChange.getLong("myValue");
  }
}

Usually you restore your state in onCreate(). It is possible to restore it in onRestoreInstanceState() as well, but not very common. (onRestoreInstanceState() is called after onStart(), whereas onCreate() is called before onStart().

Use the put methods to store values in onSaveInstanceState()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!