0
類屬性當您嘗試修改會發生什麼/讀取來自loadInBackground()
方法的類屬性。怎麼了?機器人是否傳遞變量之前進行深拷貝?當你修改AsyncTaskLoader
裏面做loadInBackground()
修改實際上改變的類屬性值?
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Void>
{
public List<String> some_array = new ArrayList();
public String some_string = "Hello world";
...
@Override
public Loader<Void> onCreateLoader(int id, Bundle args)
{
return new AsyncTaskLoader<Void>(MainActivity.this)
{
@Override
protected void onStartLoading()
{
forceLoad();
}
@Override
public Void loadInBackground()
{
some_array.add("some element");
some_string = "good bye";
}
};
}
@Override
public void onLoadFinished(Loader<Void> loader, Void data)
{
// what are the values of some_array and some_string now?
}
@Override
public void onLoaderReset(Loader<Void> loader)
{
}
}