Loader unable to retain itself during certain configuration change

前端 未结 4 620
渐次进展
渐次进展 2020-12-13 06:59

According to http://developer.android.com/guide/components/loaders.html, one of the nice thing about loader is that, it is able to retain its data during configuration chang

4条回答
  •  渐次进展
    2020-12-13 07:43

    Try to change,

     @Override
    public void onResume()
    {
        super.onResume();
    
        if (result == null) {
            // Prepare the loader.  Either re-connect with an existing one,
            // or start a new one.
            getLoaderManager().initLoader(0, null, this);
        } else {
            // Restore from previous state. Perhaps through long pressed home
            // button.
        }
    }    
    

    to

     @Override
    public void onResume()
    {
        super.onResume();
    
    Loader loader = getLoaderManager().getLoader(0); 
    if ( loader != null && loader.isReset() ) { 
        getLoaderManager().restartLoader(0, getArguments(), this); 
    } else { 
        getLoaderManager().initLoader(0, getArguments(), this); 
    } 
    
    }    
    

提交回复
热议问题