我正在使用 调用一个活动startActivityForResult(intent, 0);
,然后在更改日历视图时设置我的活动结果,然后finish();
对该活动进行 ing。但是当我调用startActivityForResult();
它需要永远加载活动。这是我如何启动 SecondActivity: 在 oncreate 中:
calendar = new Intent(Intent.ACTION_GET_CONTENT).setClass(this, CalendarShow.class);
并以一甩手势:
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
startActivityForResult(calendar, 0);
return true;
}
这是第二个活动的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
setContentView(R.layout.activity_calendar_show);
CalendarView v = new CalendarView(this);
Intent intent = getIntent();
v.setFocusedMonthDateColor(Color.BLACK);
v.setUnfocusedMonthDateColor(Color.GRAY);
v.setSelectedWeekBackgroundColor(Color.TRANSPARENT);
v.setWeekNumberColor (Color.TRANSPARENT);
v.setLayoutParams(new RelativeLayout.LayoutParams(400, 400));
v.setId(99);
v.setOnDateChangeListener(new OnDateChangeListener(){
@Override
public void onSelectedDayChange(CalendarView view, int year,
int month, int dayOfMonth) {
Intent ret = new Intent();
ret.putExtra("year", year);
ret.putExtra("month", month);
ret.putExtra("day", dayOfMonth);
setResult(RESULT_OK, ret);
finish();
overridePendingTransition(R.anim.slide_in_up2, R.anim.slide_out_up2);
}
});
RelativeLayout layout = (RelativeLayout)findViewById(R.id.calendarLayout);
layout.addView(v);
}
编辑:我尝试正常启动活动,没有 ForResult,它仍然很慢。