我正在使用另一个类在主活动显示时运行一些后台任务,并将该活动的上下文传递给此后台类。我从这个后台类启动了另一个活动,但无法调用overridePendingTransition
,因为“方法overridePendingTransition(int,int)未定义为BackgroundClass类型。”
public class GetUPC extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute()
{
...
}
@Override
protected Void doInBackground(Void... arg0)
{
...
boolean dairy;
if(theDairy.equals("N"))
{
//milk test
dairy=true;
}
else
{
dairy=false;
}
//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);
overridePendingTransition(R.layout.fade_in, R.layout.fade_out); //THIS PART ISN'T WORKING//
}
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);
}
Log.e("KYLE_DATA_UPCH",str_name+" "+str_price+""+str_size);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
else
{
Log.e("ServiceHandler", "Couldn't get any data from the url");
_errorCode=3;
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
...
}
}