在不同的情况下,我收到以下消息的错误:
我正在编写一个应用程序,其中两个 Activity 相互交互。 Activity-A 使用 Intent 启动 Activity-B。此 Activity-B 类有两个 fragment 子级。 Fragment-A 使用公共(public) Activity 方法启动另一个 Fragment-B。
public void beginTransaction(ID id, Bundle bundle) {
Fragment fragment = getFragmentItem(id);
// In case this activity was started with special instructions from an Intent,
// pass the Intent's extras to the fragment as arguments
fragment.setArguments(bundle);
// Add the fragment to the 'fragment_container' FrameLayout
fragmentManager.beginTransaction()
.add(R.id.fragment_container, fragment).commitAllowingStateLoss();
}
Fragment-B 每次调用 finish() 杀死 Activity-B,因此控制再次回到 Activity-A。并重复相同的过程。做了 2-3 次后,我得到:
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState E/AndroidRuntime( 9008): at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1354) E/AndroidRuntime( 9008): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1372)
为了避免它,我遵循 https://stackoverflow.com/a/10261438/2624806它开始给我
Java.lang.IllegalStateException: Activity has been destroyed E/AndroidRuntime( 9235): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1376) E/AndroidRuntime( 9235): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
任何我在这里遗漏的建议。
知道了 我得到了解决方案..这是在添加 fragment 的交易中发生的错误。我使用 .add 而不是使用 .replace (因为我要求不维护堆栈)并使用 commitAllowTransaction 来提交它。我读了http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html以及,似乎我所做的可能代价高昂,但对于正常的 fragment 交易,提及变通工作很好。
最佳答案
由于声誉点数较少,我无法对您的问题发表评论。 我假设这是您更改 fragment 的公共(public)方法。
public void beginTransaction(ID id, Bundle bundle)
每次您将 fragment 添加到 Activity 时,在这个方法中。因此,如果您是第一次添加 fragment ,这会很好,但如果是第二个 fragment ,您应该使用替换而不是添加
fragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment).commitAllowingStateLoss();
我认为这样做之后你应该不会遇到这个问题。或者您可以对第一个和第二个 fragment 使用“替换”。 我希望这能帮到您。
关于android - java.lang.IllegalStateException(在onSaveInstanceState之后不能执行这个 Action ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25486656/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我知道您通常应该在Rails中使用新建/创建和编辑/更新之间的链接,但我有一个情况需要其他东西。无论如何我可以实现同样的连接吗?我有一个模型表单,我希望它发布数据(类似于新View如何发布到创建操作)。这是我的表格prohibitedthisjobfrombeingsaved: 最佳答案 使用:url选项。=form_for@job,:url=>company_path,:html=>{:method=>:post/:put} 关于ruby-on-rails-rails:Howtomak
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我有一个rubyonrails应用程序。我按照facebook的说明添加了一个像素。但是,要跟踪转化,Facebook要求您将页面置于达到预期结果时出现的转化中。即,如果我想显示客户已注册,我会将您注册后转到的页面作为成功对象进行跟踪。我的问题是,当客户注册时,在我的应用程序中没有登陆页面。该应用程序将用户带回主页。它在主页上显示了一条消息,所以我想看看是否有一种方法可以跟踪来自Controller操作而不是实际页面的转化。我需要计数的Action没有页面,它们是ControllerAction。是否有任何人都知道的关于如何执行此操作的gem、文档或最佳实践?这是进入布局文件的像素
我在用Ruby执行简单任务时遇到了一件奇怪的事情。我只想用每个方法迭代字母表,但迭代在执行中先进行:alfawit=("a".."z")puts"That'sanalphabet:\n\n#{alfawit.each{|litera|putslitera}}"这段代码的结果是:(缩写)abc⋮xyzThat'sanalphabet:a..z知道为什么它会这样工作或者我做错了什么吗?提前致谢。 最佳答案 因为您的each调用被插入到在固定字符串之前执行的字符串文字中。此外,each返回一个Enumerable,实际上您甚至打印它。试试
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht