1

In my app, when the user is posting a request he also needs to set the deadline. So when the deadline is due, I want the app to delete that request automatically. I haven't tried anything yet coz I cant find anything similar to what i need.

I'll at least show the code when the user posts a request

post = (Button) myView.findViewById(R.id.post);
        post.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (ContextCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),android.Manifest.permission.ACCESS_COARSE_LOCATION)) {
                        ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSION_REQUEST_LOCATION);
                    }
                    else {
                        ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSION_REQUEST_LOCATION);
                    }
                }
                else {
                    LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
                    Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    try {
                        uloc = hereLocation(location.getLatitude(), location.getLongitude());
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                        //Toast.makeText(getActivity(), "NOT FOUND", Toast.LENGTH_SHORT).show();
                    }

                }
                dead = deadline.getText().toString();
                r = reqdesc.getText().toString();

                if(reqdesc.getText().toString().trim().length()==0){
                    Toast.makeText(getActivity(), "PLEASE ENTER YOUR REQUEST", Toast.LENGTH_LONG).show();
                }
                else if(click==0 || dl==null){
                    Toast.makeText(getActivity(), "PLEASE SET THE DEADLINE FOR YOUR REQUEST", Toast.LENGTH_LONG).show();
                }
                else {
                    String date = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
                    writeNewRequest(r, dead, uemail, uid, uname, uprofile, uloc, date);
                    String reqKey = p.getKey().toString();
                    writeDuplicate(reqKey, r, dead, uemail, uid, uname, uprofile, uloc, date);
                    Intent i = new Intent(getActivity(), RequestConfirm.class);
                    i.putExtra("key", reqKey);
                    startActivity(i);
                    //showNotification();
                }
            }
        });
AL.
  • 36,815
  • 10
  • 142
  • 281
exc3m
  • 99
  • 1
  • 1
  • 7

1 Answers1

0

Databases in general are unable to implement such time-based functionality on their own.

You have two possible courses of action:

  1. Run a maintenance app on a server, which loads the list with request's deadlines and deletes requests when their deadline is due. You run this 24/7 on 1sec time loop for example, but you don't check the deadlines in the db each second - you maintain a list by reacting to inserts, deletes and updates (you can just leave a connection to firebase open and observe a ref and it will tell you when it changes).

  2. Make additional check / modify your queries to ignore items that are past the deadline. Run a housekeeping routine once a day for example, that deletes these items.

Velko Ivanov
  • 83
  • 2
  • 4