android:when run onLoadFinished in orientation cha

2019-09-20 03:47发布

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条回答
对你真心纯属浪费
2楼-- · 2019-09-20 04:15

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.

查看更多
登录 后发表回答