在的ActivityGroup,如何恢复previous活动(无需重新启动) [英] In ActivityGroup, how to restore the previous activity(without restarting)

查看:126
本文介绍了在的ActivityGroup,如何恢复previous活动(无需重新启动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经在表4活动的ActivityGroup。

A1-> A2-> A3-> A4

假设我preSS从正在重新启动previous活动的活动回来。我要求我的呼唤一个新的活动应该开始新鲜。当我preSS的后退按钮时,previous活动都被恢复(无需重新启动)。

请帮我在这。即时缺乏适当的设置标志意向。我的code是这样的。

 公共无效startChildActivity(字符串ID,意图意图){        窗口窗口;
        Log.e(startChildActivity,startChildActivity);            窗口= getLocalActivityManager()startActivity(同上,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));            如果(窗口!= NULL)
            {
                mIdList.add(ID);                的setContentView(window.getDecorView());
            }
    }
        公共无效finishFromChild(活动子)
    {
        restartFlag = TRUE;        Log.e(finishFromChild,finishFromChild);
        LocalActivityManager经理= getLocalActivityManager();        INT指数= mIdList.size() - 1;        如果(指数< 1){            完();            返回;
        }        manager.destroyActivity(mIdList.get(指数),TRUE);        mIdList.remove(索引);        指数 -​​ ;        字符串lastId = mIdList.get(指数);        意向lastIntent = manager.getActivity(lastId).getIntent();        窗口newWindow = manager.startActivity(lastId,lastIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));        的setContentView(newWindow.getDecorView());    }


解决方案

您好我finaly了一个解决方案。其实罪魁祸首是

  manager.destroyActivity(mIdList.get(指数),TRUE);

在code。

有Android中destroyActivity()函数implement执行的错误。

问题的确切来源是code在LocalActivityManager.java以下块:

 公共窗口destroyActivity(字符型,布尔完成){
    LocalActivityRecord R = mActivities.get(ID);
    窗口赢= NULL;
    如果(R!= NULL){
        赢= performDestroy(R,完成);
        如果(完成){
            mActivities.remove(R);
        }
    }
    返回取胜;
}

变量mActivities是包含活动记录的HashMap和它使用()传递给startActivity的ID作为关键。在该方法中,对象传递的关键是LocalActivityRecord代替的ID字符串。这导致散列映射没有找到条目,因此不将其移除。

更多信息请参考此链接。 HTTP://$c$c.google.com/p /安卓/问题/细节?ID = 879More

I have an ActivityGroup which has 4 activities in a Tab.

A1->A2->A3->A4

Suppose i press back from any activity the previous activity is being restarted. my requirement when i call a new Activity it should be started fresh. and when i press the back button , the previous activity has to be restored(without restarting).

Please help me on this . im lacking in setting appropriate Intent Flags. my code goes like this.

      public void startChildActivity(String Id, Intent intent) {

        Window window;
        Log.e("startChildActivity","startChildActivity");

            window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

            if (window != null) 
            {
                mIdList.add(Id);

                setContentView(window.getDecorView());
            }


    } 


        public void finishFromChild(Activity child) 
    {
        restartFlag=true;

        Log.e("finishFromChild","finishFromChild");
        LocalActivityManager manager = getLocalActivityManager();

        int index = mIdList.size()-1;

        if (index < 1) {

            finish();

            return;
        }

        manager.destroyActivity(mIdList.get(index), true);

        mIdList.remove(index);

        index--;

        String lastId = mIdList.get(index);

        Intent lastIntent = manager.getActivity(lastId).getIntent();

        Window newWindow = manager.startActivity(lastId, lastIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

        setContentView(newWindow.getDecorView());

    }

解决方案

Hi I finaly got a solution for this . actually the culprit is

   manager.destroyActivity(mIdList.get(index), true); 

in the code.

there is a bug in Android destroyActivity() function impl .

The exact source of the problem is in the following chunk of code in LocalActivityManager.java:

public Window destroyActivity(String id, boolean finish) {
    LocalActivityRecord r = mActivities.get(id);
    Window win = null;
    if (r != null) {
        win = performDestroy(r, finish);
        if (finish) {
            mActivities.remove(r);
        }
    }
    return win;
}

The variable mActivities is the hashmap containing the activity records and it uses the id passed into startActivity() as the key. In this method, the object passed in for the key is a LocalActivityRecord instead of the id string. This results in the hashmap not finding the entry and thus not removing it.

More info refer this link. http://code.google.com/p/android/issues/detail?id=879More

这篇关于在的ActivityGroup,如何恢复previous活动(无需重新启动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆