在我的应用程序中,当用户发布请求时,他还需要设置截止日期。因此,当截止日期到期时,我希望应用程序自动删除该请求。我还没有尝试过任何东西,因为我找不到与我需要的相似的东西。
当用户发布请求时,我至少会显示代码
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();
}
}
});