我们如何知道在解析类中是否添加了新行

时间:2017-11-04 16:36:34

标签: android parse-platform

我使用解析作为我的后端。我每隔10秒就会重复一次我的活动。据我所知,在列表中保存parseobject并使用它来知道是否将新列表添加到解析类中。现在我想做三件事

  • 显示通知并更新回收站视图(如果添加了新行)
  • 更新回收者视图(如果一行被删除)
  • 更新回收者视图(如果上述情况均未发生)

我创建了两个ArrayList即。

    private List<Rqst_G_S> list = new ArrayList<>();   // Parse List
    private List<Rqst_G_S> updatedList = new ArrayList<>();  //Local List  

以下是我正在做的事情

  if (updatedList.size() > list.size()) {
            recyclerView.setNestedScrollingEnabled(false);
            VR_Adapter load = new VR_Adapter(ViewRequests.this, list);
            LinearLayoutManager layoutManager = new LinearLayoutManager(ViewRequests.this);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(load);
            updatedList = list;

            Log.i("sandeep123", String.valueOf(updatedList.size() + "1 " + list.size()));

        } else if (updatedList.size() < list.size()){
            Intent i = new Intent(ViewRequests.this, ViewRequests.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(ViewRequests.this, (int) System.currentTimeMillis(), i, PendingIntent.FLAG_ONE_SHOT);

            NotificationCompat.Builder noti = null;
            noti = new NotificationCompat.Builder(getApplicationContext())
                    .setContentTitle("Requester Requested You")
                    .setContentText("From ")
                    .setStyle(new NotificationCompat.BigTextStyle().bigText("From "))
                    .setAutoCancel(true)
                    // .setSound( Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.clean))
                    .setOnlyAlertOnce(true)
                    .setOngoing(false)
                    .setPriority(Notification.PRIORITY_MAX)
                    .setContentIntent(pendingIntent)
                    .setColor(Color.parseColor("#1ABC9C"))
                    .setSmallIcon(R.drawable.icon);


            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            assert noti != null;

            notificationManager.notify((int) SystemClock.currentThreadTimeMillis(), noti.build());
            recyclerView.setNestedScrollingEnabled(false);
            VR_Adapter load = new VR_Adapter(ViewRequests.this, list);
            LinearLayoutManager layoutManager = new LinearLayoutManager(ViewRequests.this);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(load);
            updatedList = list;

            Log.i("sandeep1234", String.valueOf(updatedList.size() + "2 " + list.size()));
        }else {
            recyclerView.setNestedScrollingEnabled(false);
            VR_Adapter load = new VR_Adapter(ViewRequests.this, list);
            LinearLayoutManager layoutManager = new LinearLayoutManager(ViewRequests.this);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(load);
            Log.i("sandeepabc", String.valueOf(updatedList.size() + "1 " + list.size()));
        }  

当应用程序第一次运行时,会显示通知,但之后每当解析列表大于更新时,列表通知都不会显示。任何猜测我做错了。

1 个答案:

答案 0 :(得分:0)

您的问题是使用非常含糊的语言。 但我想你想从Parse后端获取更新列表并在你的UI上更新它?如果是,则流程如下:

1.启动活动时,启动将继续发布的handler   从runnable获取后端列表。使用handler.postDelayed()来   在所需时间后执行获取。

2.更新对象列表后,使用新列表覆盖用于创建recylerview的数据集,并在适配器上使用notifyDatasetChanged()。