我正在调用以下函数来添加日历事件(主要取自 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();
}
}
完成此 Intent 后,我想手动刷新我的列表 Activity ,该 Activity 仅保存所有用户事件的列表(我希望它立即反射(reflect)更改)。有谁知道有什么方法可以做到这一点?是否有任何特定的函数在完成此 Intent 时被调用,我可以修改?
最佳答案
最好的选择是使用 startActivityForResults(Intent, id)
static private final int CALENDAR_DONE 101;
startActivityForResults(l_intent, CALENDAR_DONE);
然后将此函数添加到您的 Activity 中:
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;
}
}
关于java - Android 日历 Intent 完成后执行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13501759/