[英]Android startActivityForResult very slow
I am calling an activity using startActivityForResult(intent, 0);
我正在使用startActivityForResult(intent, 0);
调用活动startActivityForResult(intent, 0);
, and then setting the result of my activity when a calendarview is changed and then finish();
,然后在更改日历视图然后设置finish();
时设置我的活动结果finish();
ing the activity. 活动。 But when I call startActivityForResult();
但是当我调用startActivityForResult();
it takes forever to load the activity.Here is how I launch the SecondActivity: in the oncreate: 这将永远花费很多时间来加载活动。以下是我在oncreate中启动SecondActivity:的方法:
calendar = new Intent(Intent.ACTION_GET_CONTENT).setClass(this, CalendarShow.class);
and on a fling gesture: 并以挥舞的姿态:
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
startActivityForResult(calendar, 0);
return true;
}
Here is code for the second activity: 这是第二个活动的代码:
@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);
}
EDIT: I tried starting the activity just normal, without the ForResult and it was still slow. 编辑:我试图正常启动活动,没有ForResult,它仍然很慢。
好的,因此您不应该以挥动手势开始活动,并且这样做时加载时间很长,因此可以将活动更改为片段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.