我是否需要使用堆叠活动?

时间:2015-01-17 12:22:31

标签: android android-activity

我在这里遇到问题,我不知道为什么会这样。

activity A - login
activity B - list
activity C - profile

1. I have an activity A, B and C.
2. From activity A, I can open activity B.
3. From activity B, i can open activity C.
4. When I press the back from activity C, it goes back to activity A and I want it to be in activity B. 
来自活动C的

片段:

@Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
    }
来自活动B的

摘录:

@Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            Log.d("Clicked item id", " "+ id); 
            Intent i = new Intent(getApplicationContext(), ChildProfile.class);
            startActivity(i);
            finish();
            }
来自活动A的

片段:

 Intent i = new Intent(getApplicationContext(),Children.class);
                      startActivity(i);
                      finish();

2 个答案:

答案 0 :(得分:1)

当你打开活动C你正在完成活动B

所以只需从Activity B类代码中删除finish()即可。当你调用意​​图时

有关更多信息,请参阅以下链接

http://developer.android.com/guide/components/tasks-and-back-stack.html

答案 1 :(得分:1)

加入Activity C

@Override
    public void onBackPressed() {
        // TODO Auto-generated method stub  
           Intent i = new Intent(C.this, B.class);
            startActivity(i);
          super.onBackPressed();
            }

或删除finish();

中的Activity B