如何在 onesignal notificationReceived 方法上刷新 ListFragment?

How can I refresh ListFragment on onesignal notificationReceived method?

我正在尝试在收到通知后更新 ListFragment。但我无法更新 ListFragment。 我该怎么做?

class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
    JSONObject data = notification.payload.additionalData;
    String customerName;
    String quantity;
    if (data != null) {
        customerName = data.optString("customerName", null);
        quantity = data.optString("quantity", null);
        if (customerName != null)
        {
            //Insert To Database And Update ListFragment
        }
    }
}
}

我使用此代码来更新我的片段,但它仅在我在按钮的单击事件中而不是在方法中使用时有效。

    ListFragment fr =(ListFragment) fm.findFragmentById(R.id.fragment1);
    fr.onCreate(null);

我什至尝试重新加载片段或 activity 或应用程序!

如果你需要更新 ListFragment 里面的 ListView,你需要在上面调用 getListAdapter(),然后你将收到的 ListAdapter 转换为必要的 class 并更新它。你如何做到这一点取决于片段使用的适配器类型。

顺便说一下,永远不要自己给 onCreate 打电话。它只能由 Android 框架调用。