Code example for Fragment

Methods: getLoaderManager, onActivityCreated

0
public class ContractionAverageFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>
{ 
	@Override 
	public void onActivityCreated(final Bundle savedInstanceState)
	{ 
		super.onActivityCreated(savedInstanceState);
		getLoaderManager().initLoader(0, null, this);
	} 
 
	@Override 
	public Loader<Cursor> onCreateLoader(final int id, final Bundle args)
	{ 
		final String[] projection = { ContractionContract.Contractions.COLUMN_NAME_START_TIME,
				ContractionContract.Contractions.COLUMN_NAME_END_TIME }; 
		final String selection = ContractionContract.Contractions.COLUMN_NAME_START_TIME + ">?";
		final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
		final long averagesTimeFrame = Long.parseLong(preferences.getString(
				Preferences.AVERAGE_TIME_FRAME_PREFERENCE_KEY, 
				getString(R.string.pref_settings_average_time_frame_default)));
		final long timeCutoff = System.currentTimeMillis() - averagesTimeFrame;
		final String[] selectionArgs = { Long.toString(timeCutoff) };