Created
May 15, 2017 00:44
-
-
Save julianfalcionelli/e42fe89b448fe5caed2a18dd3a35f5aa to your computer and use it in GitHub Desktop.
Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks { | |
private int LOADER_ID = 1; | |
//... | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//... | |
if (getLoaderManager().getLoader(LOADER_ID) == null) { | |
getLoaderManager().initLoader(LOADER_ID, null, this).forceLoad(); | |
} | |
else | |
getLoaderManager().initLoader(LOADER_ID, null, this); | |
} | |
} | |
@Override | |
public Loader onCreateLoader(int i, Bundle bundle) | |
return new ExampleTaskLoader(this); | |
} | |
@Override | |
public void onLoadFinished(Loader loader, Object o) | |
mTextView.setText((String) o); | |
} | |
@Override | |
public void onLoaderReset(Loader loader) | |
loader.reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment