I would like to add this to another list of questions about resultCode == 0
and requestCode == 0
.
Here is the synopsis:
NoteActivity
calls NoteSettingsActivity
using startActivityForResult()
.
I have searched the web and when I pressed back button when super.onBackPressed()
, the resultCode == 0
. Well after further researching, it seems it returns this code whenever the back button is pressed, but after botching that super.onBackPressed()
call and just simply finish()
the application the onActivityResult()
's resultCode
is still equals to 0. It goes the same with requestCode
.
Also, I tried manipulating the manifest file, I have done so many changes just to get this work but nothings works for me.
Here is the snippet. Note that I have reverted back to my previous commit so I have lost my recent modifications, but please take a look on the code I have wrote before I notice that the resultCode
is always equals to 0 (ACTIVITY_CANCELED
)
@Override
public void onNoteSettingsActivityCalled(Note note)
{
Intent intent = new Intent(this, NoteSettingsActivity.class);
intent.putExtra(NoteExtrasKey.EXTRA_NOTE_ID, note.getNoteID());
startActivityForResult(intent, NoteRequest.REQUEST_UPDATE_SETTINGS);
}
Here is when the activity detected back press:
@Override
public void onBackPressed()
{
Log.i(NoteApplication.TAG, "NoteSettingsActivity.onBackPressed() has been called.");
Intent intent = new Intent();
intent.putExtra(NoteExtrasKey.EXTRA_NOTE_REMINDENABLED , mRemindEnabled);
intent.putExtra(NoteExtrasKey.EXTRA_NOTE_REMINDEVERY , mDaysSelected);
intent.putExtra(NoteExtrasKey.EXTRA_NOTE_REMINDON , String.valueOf(mRemindDateTime));
intent.putExtra(NoteExtrasKey.EXTRA_NOTE_ID , mTargetNoteID);
if(getParent() != null)
getParent().setResult(Activity.RESULT_OK, intent);
else
setResult(Activity.RESULT_OK, intent);
super.onBackPressed();
}
Here's how NoteActivity received the resulting call.
@Override
public void onActivityResult(int result, int request, Intent intent)
{
super.onActivityResult(result, request, intent);
Log.i(NoteApplication.TAG, "NoteActivity.onActivityResult() has been called.");
Log.i(NoteApplication.TAG, "NoteActivity.onActivityResult() result = " + result + " request = " + request);
if(result == Activity.RESULT_CANCELED)
return;
switch(request)
{
case NoteRequest.REQUEST_UPDATE_SETTINGS:
if(intent == null) return;
int noteID = intent.getIntExtra(NoteExtrasKey.EXTRA_NOTE_ID, -1);
String remindOnString = intent.getStringExtra(NoteExtrasKey.EXTRA_NOTE_REMINDON);
if(remindOnString != null && !remindOnString.equals(""))
mRemindDateTime = Timestamp.valueOf(remindOnString);
mHasSettingsEnabled = true;
mRemindEnabled = intent.getBooleanExtra(NoteExtrasKey.EXTRA_NOTE_REMINDENABLED, false);
mSelectedDays = intent.getIntegerArrayListExtra(NoteExtrasKey.EXTRA_NOTE_REMINDEVERY);
if(noteID < 0)
{
Note note = mNoteDatabaseHelper.getNote(noteID);
note.setRemindEnabled(mRemindEnabled);
note.remindEvery(mSelectedDays);
note.remindOn(mRemindDateTime);
onNoteItemUpdated(note);
}
Log.i(NoteApplication.TAG, "NoteActivity.onActivityResult() NoteRequest.REQUEST_UPDATE_SETTINGS called.");
break;
default:
Log.i(NoteApplication.TAG, "NoteActivity.onActivityResult() : unknown request code = " + request);
break;
}
}
resultCode
equals 0 and requestCode
requals -1 when I ran this. I have checked the intent passed on this and it is not null.
Here are the questions very related to this question. None of them worked:
- Android onActivityResult is always 0
- How do I handle the back button when startActivityForResult is active?
- setResult does not work when BACK button pressed
- Android: startActivityForResult always gets a resultCode of 0?
- Android Calendar: onActivityResult's resultCode is always 0
- onActivityResult always returns 0
- onActivityResult() is being called at an unexpected time
- Android - startActivityForResult immediately triggering onActivityResult
- onActivityResult() called prematurely
- Activity result is always 0
- Android: Gallery intent returning resultCode == RESULT_CANCELED Android on activity result always return 0 and null intent
I am losing a lot of important hours working on my project just figuring out what makes the value for resultCode and requestCode lose the value I sent along the way.
Any help and guidance will be appreciated. Thank you very much!