onCreate()
我对函数中的数据一致性有一个小问题。为了更好地理解我的例子:
public class Test extends Activity {
public String isThisConsistent1;
public int isThisConsistent2;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.Test, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.Item_1:
getSomething();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Test);
/*Very, very long taking code like a huge loop */
isThisConsistent1 = ...;
isThisConsistent2 = ...;
}
private void getSomething(){
String test1 = isThisConsistent1;
int test2 = isThisConsistent2;
}
}
onCreate()
所以我的问题是:是否可以在功能完成之前单击我的 ActionBar 上的项目?因为那时我会在函数getSomething()
中设置数据之前调用该onCreate()
函数。