我在两个活动之间有一个共享元素,工作正常,Activity
A是主人(包含RecyclerView
),Activity
B是详细信息。有时我需要在详细模式下更改数据,并且我希望在重新转换之前将此更改应用于Activity
A,但是在更改之后,当我按下应用崩溃时通知Adapter
,我使用LocalBroadcastManager
来反映更改,这是崩溃日志:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.transformMatrixToGlobal(android.graphics.Matrix)' on a null object reference
at android.view.GhostView.calculateMatrix(GhostView.java:95)
at android.app.ActivityTransitionCoordinator$GhostViewListeners.onPreDraw(ActivityTransitionCoordinator.java:951)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2435)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1343)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6853)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:825)
at android.view.Choreographer.doCallbacks(Choreographer.java:619)
at android.view.Choreographer.doFrame(Choreographer.java:579)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:811)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:6102)
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:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
活动A(我更新我的用户界面):
@Override
public void onReceive(Context context, Intent intent) {
int index = intent.getIntExtra(Constants.EXTRA_ORDER_INDEX, -1);
if (index != -1) {
Order order = intent.getParcelableExtra(Constants.EXTRA_ORDER);
if (order != null) {
OrderItem orderItem =
(OrderItem) mItemsAdapter.getAdapterItems().get(index);
orderItem.setOrder(order);
mItemsAdapter.notifyItemChanged(index);
}
}
}
我尝试过但不起作用:
1.我在id
中更改了子视图中的transitionName
和RecyclerView
2.在onResume
中通知我的适配器,但转换后应用了更改
3.调用setLayoutFrozen
和结果#2
注意:我需要在重新转换之前应用更改,不要想要在转换后更新UI。
这是正确的方法吗?知道我错过了什么吗?
如果您需要更多详细信息来帮助我,请告诉我,谢谢