I develop an Android application that prompt the calendar application to edit events.
I use startActivityForResult()
to open the Calender. After editing and saving the event, resultCode
is always 0 inside onActivityResult()
.
I saw many answers related to "onActivityResult resultCode always returns 0".
This is because of not using the setResult()
and finish()
in the 2nd activity.
But in my case, I am calling the Android calendar application (not a custom activity).
The code to prompt the Android calendar:
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
//set the event details
startActivityForResult(intent,1);
To trigger when calender is saved or cancelled
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//resultCode always returns 0.
switch(requestCode) {
case 1:
if (resultCode == Activity.RESULT_OK)
{
}
}
}
Whether I click "Save" or "Cancel" in the calendar app, the resultCode
always gives 0.
additionally I need to get the data back from the calendar intent.But The intent "data" in the onActivityResult also returns null.
Could anyone explain why it happens? Is there any way to know if user clicks "Save" or "Cancel"?