保存簡單的變量,這是我的問題,當我創建android系統,例如一個片段讓我們說:在Android的碎片
GastosSectionFragment gastosFragment = new GastosSectionFragment();
Fragment.gastosFragment.darUserID(userKey);
我發送一個簡單的整數該活動,沒有任何問題。例如讓我說我發送數字1.它將被存儲在該類的屬性中,因爲我創建了該片段。 一切都會正常工作,我收到號碼。但是當我旋轉手機時,變量「userKEY將丟失,它將轉換爲cero」當我水平旋轉手機時,我無法保存該號碼,如何保存該變量的數據。
這裏我把我怎麼收到的片段裏面的「用戶鑰」的代碼,
public long darUserID(long userKey) {
// TODO Auto-generated method stub
return user_id = userKey;
}
並與onCreate方法的屬性。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_section_gastos,
container, false);
idStatico = darUserID(user_id);
而且我無法保存那個小號碼。這不是一個FragmentActivity,這個類只是一個片段。第一次罰款,旋轉屏幕丟失了我以前收到的號碼。片段沒有OnSaveBundleInstances。
我會嘗試集裝箱活動中存放。 –