完成Android日历意图后执行操作

时间:2012-11-21 20:40:53

标签: java android android-intent google-calendar-api

我正在调用以下函数来添加一个Calendar事件(主要来自roman10):

private void addEvent() {
    Intent l_intent = new Intent(Intent.ACTION_EDIT);
    l_intent.setType("vnd.android.cursor.item/event");
    l_intent.putExtra("title", "roman10 calendar tutorial test");
    l_intent.putExtra("description", "This is a simple test for calendar api");
    l_intent.putExtra("eventLocation", "@home");
    l_intent.putExtra("beginTime", System.currentTimeMillis());
    l_intent.putExtra("endTime", System.currentTimeMillis() + 1800*1000);
    l_intent.putExtra("allDay", 0);
    l_intent.putExtra("eventStatus", 1);
    l_intent.putExtra("visibility", 0);
    l_intent.putExtra("transparency", 0);
    l_intent.putExtra("hasAlarm", 1);

    try {
        startActivity(l_intent);
    } catch (Exception e) {
        Toast.makeText(this.getApplicationContext(), "Sorry, no compatible calendar is found!", Toast.LENGTH_LONG).show();
    }
}

完成此意图后,我想手动刷新我的列表活动,它只包含所有用户事件的列表(我希望它立即反映更改)。有谁知道这样做的方法?在完成我可以修改的这个意图时是否有任何特定的功能被调用?

1 个答案:

答案 0 :(得分:3)

您最好的选择是使用startActivityForResults(Intent,id)

static private final int CALENDAR_DONE 101;
startActivityForResults(l_intent, CALENDAR_DONE);

然后将此功能添加到您的活动中:

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

    switch (reqCode) {
      case (CALENDAR_DONE) :
        if (resultCode == Activity.RESULT_OK) {
          //Do stuff here
        }       
      break;
    }
  }