点击后退按钮,但不能杀灭活性,让它在返回堆栈(安卓)堆栈、它在、活性、按钮

2023-09-12 04:50:36 作者:自找的痛就别喊疼〆、

我有3个活动A,B和C。

I have 3 activities A, B and C.

我动态充气活动B上的一个按钮,点击一下,因为他喜欢的用户可以添加尽可能多的观点。

I inflate activity B dynamically on a button click and the user can add as many views as he likes.

的操作是这样的:

用户看到活动先进入他的详细信息并点击保存按钮,我带他去活动B,他补充说某些领域尽可能多的时候,他喜欢当他需要再次点击保存我带他去活动Ç 。

User sees "Activity A" first enters his details and clicks the save button and I take him to "Activity B" where he adds certain fields as many times he likes and when he clicks save again I take him to "Activity C".

现在,当我在A和去B和添加一些看法和TextViews输入文字,然后点击保存,然后转到C.从C如果我打回来我见B完好以及所有充气的意见和输入的文本很明显,因为它保存在返回堆栈,但如果我去从B到A击中背部,然后再回来为B都消失了各方面的意见,因为它是从返回堆栈中移除。

Now when I am at A and go to B and add some views and enter text in TextViews and then hit save and go to C. From C if I hit back I see B intact along with all the inflated views and entered text obviously because it is saved in the Back Stack, but if I go from B to A by hitting back and then come back to B all the views are gone because it is removed from the Back Stack.

我想知道是否有可能在BackStack按住B只有一个实例,当用户点击后面不能杀死它呢? 我已经重写返回键,但无济于事,因为该活动反正打死,有些人建议我应该从它的整个观点和数据保存到Parcelable ArrayList和中的onCreate再重新生成它们,但是,这并不期待可行的我,因为我觉得我们可以将其保存在BackStack反正。

I wanted to know if it is possible to hold only one instance of B in the BackStack and not kill it at all when the user hits back? I had overriden back key but to no avail because the activity is killed anyways, some people suggested that I should save the entire views and data from it to a Parcelable ArrayList and regenerate them again in onCreate but that doesnt look feasible to me as I think we can save it in BackStack anyway.

我来到这个指南在整个Android开发 HTTP: //developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html 它说这些活动属性

I came across this guide at android developers http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html which says about these activity attributes

android:taskAffinity
android:launchMode
android:allowTaskReparenting
android:clearTaskOnLaunch
android:alwaysRetainTaskState
android:finishOnTaskLaunch
android:singleTask
android:singleInstance

但我不知道如何把他们使用。

But I am unaware of how to put them to use.

有没有人尝试过​​这一点了吗?如果是的话,请帮我把拼在一起。

Has anyone tried this out yet? If so please help me put the pieces together.

推荐答案

是的,我同意Nandeesh。

Yes,I agree with Nandeesh.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
            switch(keyCode)
            {
            case KeyEvent.KEYCODE_BACK:
                //bring back the previous activity do your logic here           
                return false; //means you don't want to remove the activity from stack 
            }
        return super.onKeyDown(keyCode, event);  // means u want to remove the last activity from Activity stack.
    }

    so question  is that how u can go to other activity without remove it from stack, 
    you can use  :
                Intent myIntent = new Intent(CurrentClass.this, JumptoActivity.class);
                 startActivity(myIntent);*

example: at the switch case u can use this

if(KeyEvent.KEYCODE_BACK)
{
                Intent myIntent = new Intent(CurrentClass.this, NextActivity.class);
                 startActivity(myIntent);
                return false;
}
else
    return true;       //if you not write this then your  menu and other think will be affected.

感谢你,我觉得这一点的信息将是û有帮助的。

Thank you I think this little bit information will be helpful for u.