安卓:当运行在onLoadFinished方向改变 [英] android:when run onLoadFinished in orientation change
问题描述
我从AsyncLoader在我的应用程序使用。
我想知道onLoadFinished运行后的方向变化期间,我的片段的方法是什么?
我展示一个对话框时加载运行首次
@覆盖
公共装载机< ArrayList的<&HashMap的LT;弦乐,对象>>> onCreateLoader(INT ID,捆绑软件包)
{
handler.sendEmptyMessage(SendRequestLoader.ShowDialog);
返回装载机;
}
我listarray添加到我的适配器
@覆盖
公共无效onLoadFinished(装载机< ArrayList的<&HashMap的LT;弦乐,对象>>>装载机,ArrayList的<&HashMap的LT;弦乐,对象>>清单)
{
Log.e(,--- onLoadFinished ---);
如果(名单!= NULL)
Log.e(之前,------- adapter.size()----+ adapter.getCount());
如果(名单!= NULL)
{
诠释计数=则为list.size();
的for(int i = 0; I<计数;我++)
{
adapter.add(list.get(I));
}
}
handler.sendEmptyMessage(((SendRequestLoader)装载机).getMessage());
如果(名单!= NULL)
Log.e(,-------则为list.size()----+则为list.size());
Log.e(后,------- adapter.size()----+ adapter.getCount());
} @覆盖
公共无效onLoaderReset(装载机< ArrayList的<&HashMap的LT;弦乐,对象>>>装载机)
{
}
我保存对话框显示对话框状态定向change.but我不知道onLoadFinished方法的onSaveInstanceState后运行的方法或没有和我使用的管理我的装载机正确的方式?
@覆盖
公共无效的onSaveInstanceState(捆绑outState)
{
super.onSaveInstanceState(outState);
如果(isshowingDialog)
outState.putBoolean(isshow,真正的);
其他
outState.putBoolean(isshow,FALSE);
outState.putParcelable(parcle,新Parcable(adapter.getArrayList()));
}
根据您的评论:
<一href=\"http://stackoverflow.com/questions/23841474/androidwhen-run-onloadfinished-in-orientation-change?noredirect=1#comment36688007_23841474\">android:when运行onLoadFinished定向变化
块引用>要没有松动对话状态时,屏幕改变了你应该做一些工作人员的方向。
首先,在
的AndroidManifest.xml
你要设置活动
的配置变化:&LT;活动
机器人:名字=my.app.pkg.MyActivity
机器人:configChanges =方向|屏幕尺寸&GT;
&LT; /活性GT;之后,你会覆盖
onConfigurationChanged
方法在活动
类时,这一点不处理任何事情:@覆盖
公共无效onConfigurationChanged(最终配置NEWCONFIG){
super.onConfigurationChanged(NEWCONFIG);
}在这里您
活动
当用户旋转设备和方向的变化不会重新启动,你会不会失去了你的异步工作人员。I am using from AsyncLoader in my app . I want know onLoadFinished run after which method of my fragment during orientation change?
I show a dialog when loader run first time
@Override public Loader<ArrayList<HashMap<String, Object>>> onCreateLoader(int id,Bundle bundle) { handler.sendEmptyMessage(SendRequestLoader.ShowDialog); return loader; }
I add listarray to my adapter
@Override public void onLoadFinished(Loader<ArrayList<HashMap<String,Object>>> loader,ArrayList<HashMap<String,Object>> list) { Log.e("", "---onLoadFinished---"); if(list!=null) Log.e("before","-------adapter.size()----"+adapter.getCount()); if(list!=null) { int count=list.size(); for(int i=0;i<count;i++) { adapter.add(list.get(i)); } } handler.sendEmptyMessage(((SendRequestLoader)loader).getMessage()); if(list!=null) Log.e("","-------list.size()----"+list.size()); Log.e("after","-------adapter.size()----"+adapter.getCount()); } @Override public void onLoaderReset(Loader<ArrayList<HashMap<String, Object>>> loader) { }
I save dialog state for show dialog in orientation change.but i am not sure onLoadFinished method can run after onSaveInstanceState method or no and am I using a right way for manage my loader?
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); if(isshowingDialog) outState.putBoolean("isshow",true); else outState.putBoolean("isshow",false); outState.putParcelable("parcle", new Parcable(adapter.getArrayList())); }
解决方案Based on your comment: android:when run onLoadFinished in orientation change
To not loose dialog state when screen changes the orientation you should do some staff.
First in
AndroidManifest.xml
you gonna set the config changes ofActivity
:<activity android:name="my.app.pkg.MyActivity" android:configChanges="orientation|screenSize" > </activity>
After that you gonna override the
onConfigurationChanged
method in yourActivity
class to not handle anything when this happen:@Override public void onConfigurationChanged( final Configuration newConfig ) { super.onConfigurationChanged( newConfig ); }
At here your
Activity
will not be restarted when user rotate the device and orientation changes, and you not will lost your async staff.这篇关于安卓:当运行在onLoadFinished方向改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!