Last active
September 15, 2016 06:01
-
-
Save rhexgomez/78944ada05af6a61c7b3a14257151f3d to your computer and use it in GitHub Desktop.
The `onLoaderReset()` is only called when the user presses the back button and not when calling `restartLoader()`. A related issue is discussed here https://code.google.com/p/android/issues/detail?id=68896
This file contains 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<Cursor> { | |
public static final String LOG_TAG = MainActivity.class.getSimpleName(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
Log.e(LOG_TAG, "<======================calling create=======================>"); | |
getSupportLoaderManager().initLoader(1, null, this); | |
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | |
fab.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
Log.e(LOG_TAG, "<======================calling restart=======================>"); | |
getSupportLoaderManager().restartLoader(1, null, MainActivity.this); | |
} | |
}); | |
} | |
@Override | |
protected void onDestroy() { | |
super.onDestroy(); | |
Log.e(LOG_TAG, "<======================calling destroy=======================>"); | |
getSupportLoaderManager().destroyLoader(1); | |
} | |
@Override | |
public Loader<Cursor> onCreateLoader(int id, Bundle args) { | |
Log.e(LOG_TAG, "onCreateLoader()"); | |
return new CursorLoader(this, Uri.parse("content://www.test.com/a"), | |
null, null, null, null); | |
} | |
@Override | |
public void onLoadFinished(Loader<Cursor> loader, Cursor data) { | |
Log.e(LOG_TAG, "onLoadFinish()"); | |
} | |
@Override | |
public void onLoaderReset(Loader<Cursor> loader) { | |
Log.e(LOG_TAG, "onLoaderReset()"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment