android:when run onLoadFinished in orientation change

99封情书 提交于 2019-12-25 18:36:51

问题


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()));
}

回答1:


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 of Activity:

<activity
    android:name="my.app.pkg.MyActivity"
    android:configChanges="orientation|screenSize" >
</activity>

After that you gonna override the onConfigurationChanged method in your Activity 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.



来源:https://stackoverflow.com/questions/23841474/androidwhen-run-onloadfinished-in-orientation-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!