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();
}
}
});