开发者

destroyActivity() Bug in LocalActivityManager class in Android issue

I have a Tab Activity and with in Tab, im using Activity Group. and using LocalActivityManger, im trying to destroy an Activty using the following function call provided in LocalActivityManger class

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

in the code. but later i found that there is a bug in Android impl for this

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 i开发者_StackOverflow中文版d 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

and i found a work around for this issue and im using following function to fix the problem.

       public boolean destroy(String id) {

        if(manager != null){
            manager.destroyActivity(id, false);
            try {
                final Field mActivitiesField = LocalActivityManager.class.getDeclaredField("mActivities");
                if(mActivitiesField != null){
                    mActivitiesField.setAccessible(true);
                    @SuppressWarnings("unchecked")
                    final Map<String, Object> mActivities = (Map<String, Object>)mActivitiesField.get(manager);
                    if(mActivities != null){
                        mActivities.remove(id);
                    }
                    final Field mActivityArrayField = LocalActivityManager.class.getDeclaredField("mActivityArray");
                    if(mActivityArrayField != null){
                        mActivityArrayField.setAccessible(true);
                        @SuppressWarnings("unchecked")
                        final ArrayList<Object> mActivityArray = (ArrayList<Object>)mActivityArrayField.get(manager);
                        if(mActivityArray != null){
                            for(Object record : mActivityArray){
                                final Field idField = record.getClass().getDeclaredField("id");
                                if(idField != null){
                                    idField.setAccessible(true);
                                    final String _id = (String)idField.get(record);
                                    if(id.equals(_id)){
                                        mActivityArray.remove(record);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return true;
        }
        return false;
    }

now the problem is, this fix is working fine in Android API versions 2.1,2.2 and 2.3 but i tested in 3.0 . but it is failing there. no exceptions.

I want to know in which API version this bug has been fixed.

And also what fix can i make for this so that it will work fine in all the API versions after 2.1 .

Thank u

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜