[英]How to override the transition from an activity's context?
I want to override the transition from page to page from the following: In the current Activity, I'm running another class's methods in the background using my current activity's context. 我想从以下内容覆盖页面到页面的过渡:在当前活动中,我正在使用当前活动的上下文在后台运行另一个类的方法。 From that class I open up 1 of 2 possible activities (Using the context, but not directly through my initial activity). 从该类中,我打开2种可能的活动之一(使用上下文,但不直接通过我的初始活动)。 Is there a way to override the page transition from the initial activity to both new activities? 有没有办法覆盖从初始活动到两个新活动的页面转换? Because overridePendingTransition
can only be run on an activity object, I cannot just call this method in both cases, as the cases are not part of the actual activity. 因为overridePendingTransition
只能在活动对象上运行,所以我不能在两种情况下都只调用此方法,因为这些情况不是实际活动的一部分。
Sorry if this isn't so clear, feel free to ask questions that will clear up anything. 抱歉,如果不清楚,请随时提出问题以解决所有问题。 I'm still not exactly 100% on definitions of intent and context. 我对意图和上下文的定义仍然不是100%。
//depending on if there is a warning it will either display the warning screen or skip it
if(dairy)
{
Intent intent_warn = new Intent(context, WarningScreen.class);
intent_warn.putExtra("Name", str_name);
intent_warn.putExtra("Size", str_size);
intent_warn.putExtra("Price", str_price);
intent_warn.putExtra("Carbs", str_carbs);
intent_warn.putExtra("Protein", str_protein);
intent_warn.putExtra("Fiber", str_fiber);
intent_warn.putExtra("Sugar", str_sugar);
intent_warn.putExtra("SatFat", str_satFat);
intent_warn.putExtra("TotFat", str_totFat);
intent_warn.putExtra("Cholesterol", str_cholesterol);
intent_warn.putExtra("Sodium", str_sodium);
intent_warn.putExtra("Potassium", str_potassium);
intent_warn.putExtra("Calories", str_calories);
intent_warn.putExtra("Warning", "Contains Dairy");
intent_warn.putExtra("WarningRed", true);
Log.e("Warning",intent_warn.getExtras().getString("Warning"));
context.startActivity(intent_warn);
context.overridePendingTransition(R.layout.fade_in, R.layout.fade_out);
}
else
{
Intent intent_menu = new Intent(context, DisplayScreen.class);
intent_menu.putExtra("Name", str_name);
intent_menu.putExtra("Size", str_size);
intent_menu.putExtra("Price", str_price);
intent_menu.putExtra("Carbs", str_carbs);
intent_menu.putExtra("Protein", str_protein);
intent_menu.putExtra("Fiber", str_fiber);
intent_menu.putExtra("Sugar", str_sugar);
intent_menu.putExtra("SatFat", str_satFat);
intent_menu.putExtra("TotFat", str_totFat);
intent_menu.putExtra("Cholesterol", str_cholesterol);
intent_menu.putExtra("Sodium", str_sodium);
intent_menu.putExtra("Potassium", str_potassium);
intent_menu.putExtra("Calories", str_calories);
intent_menu.putExtra("Warning", "Contains no allergens");
intent_menu.putExtra("WarningRed", false);
Log.e("Warning",intent_menu.getExtras().getString("Warning"));
context.startActivity(intent_menu);
context.overridePendingTransition(R.layout.fade_in, R.layout.fade_out);
}
I tried using context.overridePendingTransition...
but that cannot be done on a context. 我尝试使用context.overridePendingTransition...
但是不能在上下文上完成。 However the following bit of code works when run from another Activity, not a context item: 但是,以下代码在从另一个Activity(而不是上下文项)运行时可以工作:
startActivity(letsMenu);
overridePendingTransition(R.layout.fade_in, R.layout.fade_out);
只需将上下文包装如下:
((Activity)context).overridePendingTransition(R.layout.fade_in, R.layout.fade_out);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.