Java 我可以将片段非默认构造函数与onSaveInstanceState方法一起使用吗
我正在创建一个片段,需要在初始化过程中接收一个对象 现在我了解到,我需要担心配置更改,因此需要使用捆绑包 我想知道的是两件事: 1) 我可以使用非默认构造函数(不使用bundle)设置片段,并仅在onSaveInstance中处理bundle部分,还是存在这样的情况? (如果需要的话,我有一个android框架的默认空构造函数) 2) 我在应用程序实例的扩展中使用数组作为管道来保存对象,这样我就不必实现parcelable接口(有很多对象需要在更改后保存和保留),这种方法有什么问题吗?如果有,还有更好的方法吗(未实现可序列化或可打包?) onCreateView:Java 我可以将片段非默认构造函数与onSaveInstanceState方法一起使用吗,java,android,android-fragments,Java,Android,Android Fragments,我正在创建一个片段,需要在初始化过程中接收一个对象 现在我了解到,我需要担心配置更改,因此需要使用捆绑包 我想知道的是两件事: 1) 我可以使用非默认构造函数(不使用bundle)设置片段,并仅在onSaveInstance中处理bundle部分,还是存在这样的情况? (如果需要的话,我有一个android框架的默认空构造函数) 2) 我在应用程序实例的扩展中使用数组作为管道来保存对象,这样我就不必实现parcelable接口(有很多对象需要在更改后保存和保留),这种方法有什么问题吗?如果有,还
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
//in case the view is restarted and we edit an existing group get the group from pipe
if (savedInstanceState!=null)
{
int itemId=savedInstanceState.getInt(GROUP_KEY);//get the pipe item key
set_group((ContactGroup)getApplication().get_pipeItem(itemId));
set_groupContactList(get_group().get_contactsInGroup());
}
View rootView = inflater.inflate(R.layout.f_add_contact_group, container,
false);
setPlaceHolders(rootView);
assignListeners();
initView();//create the people list and add it to the view
return rootView;
}
public void onSaveInstanceState(Bundle outState)
{
//save the chosen group
int id=getApplication().set_pipeItem(get_group());
outState.putInt(GROUP_KEY,id);//add the pipe id for the item to the bundle
super.onSaveInstanceState(outState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
//in case the view is restarted and we edit an existing group get the group from pipe
if (savedInstanceState!=null)
{
int itemId=savedInstanceState.getInt(GROUP_KEY);//get the pipe item key
set_group((ContactGroup)getApplication().get_pipeItem(itemId));
set_groupContactList(get_group().get_contactsInGroup());
}
View rootView = inflater.inflate(R.layout.f_add_contact_group, container,
false);
setPlaceHolders(rootView);
assignListeners();
initView();//create the people list and add it to the view
return rootView;
}