Tag: fragmentmanager

Android的FragmentManager的BackStackRecord.run抛出NullPointerException

处理碎片时,我有时会遇到以下exception: FATAL EXCEPTION: main java.lang.NullPointerException at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:591) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) 当通过execPendingTransactions()调用BackStackRecord run()时发生exception,当它试图从pipe理器中删除片段时。 case OP_REMOVE: { Fragment f = op.fragment; f.mNextAnim = op.exitAnim; <—- mManager.removeFragment(f, mTransition, mTransitionStyle); } break; 我似乎无法弄清楚究竟是什么造成了这个? 我认为这与拆卸碎片时没有正确清理碎片的背后叠加有关。

我如何访问片段中的getSupportFragmentManager()?

我有一个FragmentActivity,我想使用它内的地图片段。 我有一个问题让支持片段pipe理器来访问它。 if (googleMap == null) { googleMap = ((SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map1)).getMap(); // check if map is created successfully or not if (googleMap == null) { Toast.makeText(getApplicationContext(), "Sorry! unable to create maps", Toast.LENGTH_SHORT) .show(); } } // create marker MarkerOptions marker = new MarkerOptions().position( new LatLng(latitude, longitude)).title("Hello Maps "); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new […]