1
我有一個關於onCreate()
函數中的數據一致性的小問題。爲了更好地理解我的例子:是否可以在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()
功能之前點擊我的動作條的項目?因爲在數據在onCreate()
函數中設置之前,我會調用函數getSomething()
。
感謝您的完美回答:) – StarFighter