我在 fragment 中使用 supportMapFragment 这就是为什么我使用 this.getChildFragmentManager() 如果这个错误请指导我
public static ClinicFragment newInstance() {
ClinicFragment fragment = new ClinicFragment();
return fragment;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
setTargetFragment(null , -1); // one of my tries
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_maps, null, false);
Log.i(TAG , "onCreateView");
mapFragment = (SupportMapFragment) this.getChildFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
mapUtils = new MapUtils(getActivity());
.......
return view;
}
@Override
public void onMapReady(com.google.android.gms.maps.GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setOnMarkerClickListener(this);
}
@Override
public void onPause() {
super.onPause();
mapUtils.removeUpdate(mMap); // this helper class handle change location listener
Log.i(TAG, "onPause");
}
@Override
public void onDestroyView() {
super.onDestroyView();
Log.i(TAG, "onDestroyView");
}
@Override
public void onStop() {
super.onStop();
Log.i(TAG, "onStop");
killOldMap();
}
//remove map fragment when view disappeared
private void killOldMap() {
try{
SupportMapFragment mapFragment = ((SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map));
if(mapFragment != null) {
FragmentManager fM = getFragmentManager();
fM.beginTransaction().remove(mapFragment).commit();
}
}catch (Exception e){
e.printStackTrace();
}
}
我的日志
java.lang.IllegalStateException: Failure saving state: active SupportMapFragment{1ba0fd93} has cleared index: -1
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1824)
at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:2111)
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1767)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1835)
at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:125)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:523)
at android.app.Activity.performSaveInstanceState(Activity.java:1297)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1272)
at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:3923)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3334)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
我可以描述我的错误,它尝试删除 map fragment 但他找不到它引用
我的尝试
1- 经过长时间的研究,我找到了 setTargetFragment(null , -1); 方法。
2- 在 onStop 中杀死 fragment 。
但是所有这些尝试都不能帮助我解决我的问题,任何人都可以指导我为什么我想念
最佳答案
我不使用public static ClinicFragment newInstance()
我使用附加到 Activity 示例的 fragment 。
public class MyFragment extends Fragment
我不明白你为什么要删除你的 map fragment 。我从来不需要这样做,只是让自然 Activity 生命周期管理大多数事物的破坏。
您还在 killOldMap 之前调用 super 方法 onDestroy,这意味着在 super 方法中销毁的任务顺序将在 killOldMap 方法之前调用。这也会让资源在没有附加 Activity 的情况下悬空。
Override
public void onStop() {
super.onStop();
Log.i(TAG, "onStop");
killOldMap();
}
所以有几种方法可以解决这个问题:
删除 fragment 将导致 fragment 被销毁,而无需使用您的 kill 方法:
getActivity().getSupportFragmentManager().beginTransaction().remove(this)
.commit();
那里正在使用 fragmentTransaction.replace(R.id.yourId, fragment)
就我个人而言,我喜欢在我的 Activity 布局中使用框架布局然后切换 map 和其他 fragment 之间的可见性的想法,我不会破坏 map ,它会返回到我正在寻找的任何坐标.如果我能很好地管理定位服务,这并没有什么坏处。 这是我使用的设计选择,绝不是法律。
我通过该框架布局中 fragment 的可见性来管理任何位置调用。创建自定义方法:
public void hideFrames() {
frameLayout2.setVisibility(View.GONE);
frameLayout3.setVisibility(View.GONE);
}
框架布局通过这种方式管理 map 的可见性。
<RelativeLayout .../...
android:id="@+id/main">
<TextView
android:id="@+id/t1"
.../.../>
<FrameLayout
android:id="@+id/framelayout1"
android:layout_below="@+id/t1"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
<FrameLayout
android:id="@+id/framelayout2"
android:layout_below="@+id/t1"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:visibility="gone">
<fragment
android:id="@+id/map"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</FrameLayout>
</RelativeLayout>
并且您可以在您的父 Activity 中使用您的方法并从您的 fragment 中调用它们:
public void replaceFragment(Fragment fragment) {
hideFrames();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.YourId, fragment);
fragmentTransaction.commit();
}
它从附加到 Activity 的每个 fragment 中调用,如下所示:
// create new fragment
((MainActivity) getActivity()).replaceFragment(fragment);
还有:
这有一个已知问题
Fix issue #6584942 IllegalStateException: Failure saving state...
...active SuggestFragment{419494f0} has cleared index: -1
There were issues when the same fragment was removed and then added again before completely finishing the remove (such as due to a running animation).
关于java - 保存状态失败 : active SupportMapFragment{} has cleared index: -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34480430/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
我正在尝试使用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
对于作为String#tr参数的单引号字符串文字中反斜杠的转义状态,我觉得有些神秘。你能解释一下下面三个例子之间的对比吗?我特别不明白第二个。为了避免复杂化,我在这里使用了'd',在双引号中转义时不会改变含义("\d"="d")。'\\'.tr('\\','x')#=>"x"'\\'.tr('\\d','x')#=>"\\"'\\'.tr('\\\d','x')#=>"x" 最佳答案 在tr中转义tr的第一个参数非常类似于正则表达式中的括号字符分组。您可以在表达式的开头使用^来否定匹配(替换任何不匹配的内容)并使用例如a-f来匹配一
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht