使用意图重新开始活动

时间:2011-11-30 18:17:54

标签: android android-intent

Intent i= new Intent( SetTest.this, SetTest.this);// compile error there
i.putExtra("question_number", questionNumber++);
startActivity(i);

我想将数据发布到同一个活动中。这是我在mainfest文件中的intent过滤器:

      <activity android:name="SetTest">
         <intent-filter android:label="@string/setQuestion">
                 <action android:name="android.intent.action.VIEW" />
                 <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

我不明白为什么会出现编译错误?!?

我得到编译错误,也是这样:

 Context context=getApplicationContext();

Intent i = new Intent(context,SetTest.this);

3 个答案:

答案 0 :(得分:1)

将活动的上下文保存到成员变量,然后在意图创建中使用保存的上下文。

private Context _context;

Constructor...
{
_context = this;
}

然后在按钮回调中:

Intent i= new Intent( _context, newDesiredClass.class);

答案 1 :(得分:1)

使用此

Intent i= new Intent( SetTest.this, SetTest.Class);

希望这会起作用

答案 2 :(得分:1)

如其他答案所说:

Intent i= new Intent( SetTest.this, SetTest.Class);
i.putExtra("question_number", questionNumber++);
startActivity(i);
finish();

当您加载相同的活动时,您可能希望完成当前活动以避免导航树中出现问题