设置Intent的数据

时间:2012-10-23 13:42:51

标签: android android-intent

我有一个意图:

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

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

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

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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的详细信息,请参阅intent docs