Git Product home page Git Product logo

Comments (9)

dodola avatar dodola commented on June 12, 2024

Fragment 是需要一个默认构造方法的,在Fragment里添加一个无参的构造方法应该就可以

from android-app.

rockybean avatar rockybean commented on June 12, 2024

一般推荐是在fragment中使用一个newInstance的方法,然后把传入的参数放在fragment本身的argument中,例如

public static YourFragment newInstance(String someArg){
            YourFragment rtn = new YourFragment();
             Bundle args = new Bundle();
             args.putString("argKey",someArg);
            rtn.setArgument(args);
            return rtn;
}

之后可以从fragment的getArgument()中获取存储的方法,这样就可以很好的避免上面的问题了

from android-app.

IceskYsl avatar IceskYsl commented on June 12, 2024

楼上正解~ 大家可以尝试修复下这个问题,然后发个pull request〜

from android-app.

com360 avatar com360 commented on June 12, 2024

大家快点发pull request,我等着merge呢 ;)

from android-app.

mjkohoh avatar mjkohoh commented on June 12, 2024

尝试重现bug失败。重现环境在nexus7的4,2,2版本和4.3都跑过了。都没有出现上述所说的Force Close。请问是不是已经修复这个bug了。但是我并没有找到相关提交。

from android-app.

mjkohoh avatar mjkohoh commented on June 12, 2024

好吧这个issue的确还没有被修复。查了一下文档,出现FC的原因是因为在系统需要重新实例化fragment的时候需要一个空的构造方法。(这点之前的同学已经说过了,我又重述了一遍),而我没有重现bug的原因可能是因为没有遇到系统重新实例化fragment吧。

以下是相关文档的引用

All subclasses of Fragment must include a public empty constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the empty constructor is not available, a runtime exception will occur in some cases during state restore.


对于@rockybean 的建议,我想说的是。这会不会对代码改动太大

from android-app.

mjkohoh avatar mjkohoh commented on June 12, 2024

另外相似的问题也在issue #48 中出现。在issue #48 中解决办法是增加无参构造函数。
我想对于一个相同的问题应该采取相同的解决方法。所以有必要讨论一下到底是采用无参构造函数还是使用newInstance方法。

下面列出同样出同样有这个bug的fragment

  • UserCollectFragment
  • UserCollectListFragment
  • UserIntroFragment
  • UserLogOutFragment
  • WikiFragment

from android-app.

mjkohoh avatar mjkohoh commented on June 12, 2024

@IceskYsl @com360 你觉得采取哪种方法修复这个bug最好

from android-app.

mjkohoh avatar mjkohoh commented on June 12, 2024

没有人愿意讨论一下的吗?
要不管理员做个决定?

from android-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.