Home » Android » events – Android startActivityForResult not returning on calendar data

events – Android startActivityForResult not returning on calendar data

Posted by: admin June 15, 2020 Leave a comment

Questions:
   The code Written below works for me

                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setType("vnd.android.cursor.item/event");
                intent.putExtra("title", "Hi this me");
                intent.putExtra("description", "Some description");
                intent.putExtra("beginTime", eventStartInMillis);
                intent.putExtra("endTime", eventEndInMillis);
                startActivityForResult(intent, 1);

my question is that i can’t back the android calendar data in OnActivityResult, i don’t know why please help me for this issue.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == 1) {

     if(resultCode == RESULT_OK){

      String result=data.getStringExtra("title");

}


And i am getting data.getExtras() is null !!!!!
How to&Answers:

It s Because Result code always Return 0 In android calendar Activity result of Calendar implicit intent try using RESULT_CANCEL in onActivity result

public void onActivityResult(int reqCode, int resultCode, Intent data) {

super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {

if (resultCode == Activity.RESULT_CANCEL)

And You Have to just Check out Next Event ID it will working
Hope it will Help to you..

Govind

Answer:

If you look at the official documentation:
http://developer.android.com/reference/android/app/Activity.html#setResult(int, android.content.Intent)
you will see that the Intent you get in onActivityResult() is actually dependent on the Activity you are calling. More specifically it depends on whether the called Activity uses setResult(int, android.content.Intent) with an Intent with extras or not.

From a quick internet search it seems that the code you are using is for adding an event in the Calendar, but that does not neccessary mean that you will get the event data back from the Calendar app. Perhups you have to query the Calendar afterwards to get them.

As for the Contacts app, it specifically states so in the Contacts Provider Guide, that you can get the contact data in onActivityResult() if you use startActivityForResult. In the Calendar Provider Guide there is no such statement, so it is probably not supported.

Answer:

You can use this code:

public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
switch (reqCode) {
 if (resultCode == Activity.RESULT_OK) {
        Bundle extras = data.getExtras();
        String title=extras.getString("title");
        String description=extras.getString("description");
        String beginTime=extras.getString("beginTime");
        String endTime=extras.getString("endTime");

Answer:

The problem is you are putting the data to intent directly and retrieving it through Bundle.

Try this:

Crete a bundle object like this:

Intent i = new Intent("yourFullyQualifiedClassName");

 Bundle extras = new Bundle();
 extras.putString("title", "Hi this me");
 extras.putString("description", "Some description");
 i.putExtras(extras);

Then retrieve the data from the bundle like this:

Bundle bundle = data.getExtras();

bundle.getString("title");

Hope this solves your problem.

Answer:

It is because you are passing the data to the activity that you started (Activity B) by startActivityForResult from Activity A. onActivityResult() will only get the data passed by Activity B and not by Activity A.

Here’s a nice tutorial about android intents.

http://www.vogella.com/articles/AndroidIntent/article.html

and this site too

http://saigeethamn.blogspot.jp/2009/08/android-developer-tutorial-for_31.html