0
FAB
的onClickListener
内部的Intent
在实施LoaderManager.LoaderCallbacks<Cursor>
及其方法后使应用崩溃,但在实施这些方法之前,应用工作得很好。 为什么onCreateLoader
,onLoadFinished
和onLoaderReset
方法会使FAB
停止工作?CursorLoader是否使Intents停止工作?
注意:并非该应用程序的所有功能目前都在运行,即:删除 我仍在使用更新方法。
//The intent in the CatalogActivity "The main activity"
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent newIntent = new Intent(CatalogActivity.this, EditorActivity.class);
startActivity(newIntent);
}
//After implementing these methods the EditorActivity, the FAB in the first activity makes the app crash
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection = {
PetEntry._ID,
PetEntry.COLUMN_PET_NAME,
PetEntry.COLUMN_PET_BREED,
PetEntry.COLUMN_PET_GENDER,
PetEntry.COLUMN_PET_WEIGHT
};
return new CursorLoader(this, mCurrentPetUri, projection, null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data == null || data.getCount() < 1) {
return;
}
if (data.moveToNext()) {
String name = data.getString(data.getColumnIndex(PetEntry.COLUMN_PET_NAME));
mNameEditText.setText(name);
String breed = data.getString(data.getColumnIndex(PetEntry.COLUMN_PET_BREED));
mBreedEditText.setText(breed);
int weight = data.getInt(data.getColumnIndex(PetEntry.COLUMN_PET_WEIGHT));
mWeightEditText.setText(Integer.toString(weight));
int gender = data.getInt(data.getColumnIndex(PetEntry.COLUMN_PET_GENDER));
if (gender == PetEntry.GENDER_MALE){
mGenderSpinner.setSelection(1);
} else if (gender == PetEntry.GENDER_FEMALE) {
mGenderSpinner.setSelection(2);
} else {
mGenderSpinner.setSelection(0);
}
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mNameEditText.setText("");
mBreedEditText.setText("");
mWeightEditText.setText("");
mGenderSpinner.setSelection(0);
}
请不要只需链接到您的代码异地。您需要在问题本身中包含[mcve],以及崩溃中的堆栈跟踪。 –
将编辑该问题 –