0

我有一个意图:

Intent intentEndGame = new Intent(Class2.this, EndGame.class);

此代码属于 Class2 类。但我想使用 Class1 的类。我试图将代码更改为:

Class1 c1 = new Class1;
Intent intentEndGame = new Intent(c1, EndGame.class);

但它不起作用。拜托,你能帮帮我吗?谢谢你。

4

2 回答 2

0
Intent intentEndGame = new Intent(Class2.this, EndGame.class);
startActivity(intentEndGame);
于 2012-10-23T13:44:41.173 回答
0

您需要从 class2 调用 class1 吗?为此,您应该使用以下代码:

Intent intent=new Intent(class2.this,class1.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
/* Intent.FLAG_ACTIVITY_CLEAR_TOP If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent. */

startActivity(intent);

有关 FLAGS 的更多信息,请参阅:有关 FLAGS 的更多信息,请参阅意图文档

于 2012-10-23T13:58:30.417 回答