Android Activity Intent本身

时间:2011-12-11 14:25:03

标签: android

如何对同一个活动制作意图?

我有一个具有前进和后退按钮的Activity Lektion,当我点击前进按钮时,我想与其他参数一起启动相同的Activity。 为此,我还发送了一份意向书。

但是活动似乎不会再次被创建......

public class Lektion extends Activity {
    private int rowCount = 0;
    private ArrayList<LektionPage> lektionPages = new ArrayList<LektionPage>();
    private int lektionPage = 0;
    private Bundle bundle;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lektion);

        bundle = this.getIntent().getExtras();
        String lektionNummer = bundle.getString("LektionNummer");
        setTitle("Lektion "+lektionNummer);     

        try{
            lektionPage = bundle.getInt("LektionPage");
        } catch(Exception e){}

        forwardImageButton.setOnTouchListener(new OnTouchListener(){
            public boolean onTouch(View view, MotionEvent me) {
                if(lektionPage == rowCount){
                    return false;
                }
                Log.i("ontouch", ""+lektionPage);
                Intent intent = new Intent(Lektion.this, Lektion.class);
                bundle.putInt("LektionPage", lektionPage++);
                intent.putExtras(bundle);
                return true;
            }

        });
    }

3 个答案:

答案 0 :(得分:2)

您只是在不激活它的情况下创建意图。

你需要

startActivity(intent);

实际执行的意图。

但是id说你应该只改变活动视图的内容等而不是一遍又一遍地创建活动

答案 1 :(得分:1)

这是处理您需求的一种尴尬(也许是不可能的)方式。

考虑使用Fragments拆分功能和导航。

答案 2 :(得分:1)

我觉得这可以通过使用popper活动启动模式和活动的onNewIntent方法中的一些逻辑来实现。

Activity Launch Modes 1

Activity Launch Modes 2

我建议您为活动使用单一任务启动模式。

我希望它有所帮助..