9
   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 !!!!!
10
  • what are the data that you need? and what are you getting so far? based on the code above, you're just getting the title.
    – artsylar
    Dec 6, 2012 at 7:01
  • But Bundle extras = data.getExtras(); is returning null Dec 6, 2012 at 7:29
  • I see. Thanks for the info. I just asked because it is not written in your question.
    – artsylar
    Dec 6, 2012 at 8:05
  • have you checked your request code?
    – artsylar
    Dec 6, 2012 at 8:09
  • yes but the same problem i think calendar might not give their data Dec 6, 2012 at 8:19

5 Answers 5

1

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

1

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.

-1

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");
1
  • 1
    But the Bundle extras = data.getExtras(); is returning null Dec 6, 2012 at 7:27
-1

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.

4
  • But Bundle bundle = getIntent().getExtras(); is returning null Dec 6, 2012 at 7:30
  • @mitenjoshi I gave you somewhat generalized answer. Replace getIntent() with "data" as the intent is available directly as data in your method.
    – Kanth
    Dec 6, 2012 at 7:33
  • Yes i implemented with that but also still the same Dec 6, 2012 at 7:38
  • 1
    Show me your full code then . Edit your question or share the links that show your code. How could you get into if condition in switch statement without case? Strange.
    – Kanth
    Dec 6, 2012 at 7:41
-1

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

2
  • but i got the contactdata using the same startactivityforresult but can't get calendar data that i dont know!! Dec 6, 2012 at 9:06
  • if (resultCode == Activity.RESULT_OK) { Uri contactData = data.getData(); Cursor c = managedQuery(contactData, null, null, null, null); if (c.moveToFirst()) { String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); System.out.println("CONTACT NAME IS" + name); this code give the contact data Dec 6, 2012 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.