5

I've a home screen widget with few buttons. One of them should call (phone) calendar dialog to create new event. So i registered listener to my widget button:

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
PendingIntent pi = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
updateViews.setOnClickPendingIntent(R.id.btnAdd, pi); 

When I push this btn in my widget, it launches calendar dialog for creating new event - this is ok. But after filling all fields and pressing "Done" in calendar, I would like to return back to my app (or to home screen to my widget). Instead, I'm still inside calendar app. How to deal with this, or is it possible?

qkx
  • 2,383
  • 5
  • 28
  • 50

1 Answers1

3

You should first start an Activity of your app, which then starts this intent.

But there is a problem with the Calendar app. While it should only add activities to the back stack when started from a widget, it does so all the time. See this issue posted by me:

http://code.google.com/p/android/issues/detail?id=28704

So users would have to hit "back" twice. Well, on phones that is. If I recall it correctly (cannot test at the moment) all works fine on tablets.

Wolfram Rittmeyer
  • 2,402
  • 1
  • 18
  • 21
  • 1
    whatever u do (if u set pending intent directly to call calendar, or first call my app which then calls calendar intent) it does the same, as u're saying. That's definitely not good behavious, but what we can't do anything i suppose...Google hasn't very good docs - for example they say u can call edit intent to calendar and edit event - and this is NOT POSSIBLE (see http://stackoverflow.com/questions/13072275/using-an-intent-to-edit-calendar-event-doesnt-work/)... Sometimes it's hard with google, they say A but in reality it's B – qkx Oct 26 '12 at 13:39
  • The one of the other call is way more problematic. The Calendar app is a mess - no wonder they waited so long till they released it. If only they had used the time to correct the code. – Wolfram Rittmeyer Oct 26 '12 at 18:40
  • BTW: I added this issue some time ago to the bug tracker. If you vote for it, it might help: http://code.google.com/p/android/issues/detail?id=28704 – Wolfram Rittmeyer Oct 26 '12 at 18:53