如何在更改日期时注销用户

时间:2017-10-16 10:17:06

标签: android date alarmmanager

我正在开发一个应用,用户需要在更改日期时注销。由于我正在使用警报管理器来注销用户,但我无法执行此操作。他们是否有机会使用日期退出用户。

代码低于

AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, Login.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
Calendar timeOff = Calendar.getInstance();

/* setting time */
timeOff.set(Calendar.HOUR_OF_DAY, 23);
timeOff.set(Calendar.MINUTE, 59);
timeOff.set(Calendar.SECOND, 0);
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY,
AlarmManager.INTERVAL_DAY, intent);

2 个答案:

答案 0 :(得分:0)

使用此操作

    final IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_TIME_TICK);
    /**eg
      this.sysForbidenReceiver.checkTime(this);
      this.registerReceiver(this.sysForbidenReceiver, filter);
    **/

答案 1 :(得分:0)

在您的第一个活动onCreateMethod上使用此代码

var currentDate = LocalDateEx.getNow().toString()
        Log.d("experiment",currentDate)

        var previousDate = Utility.getEDate(this)
        Log.d("dshf",previousDate)
        if (currentDate != previousDate){

            Utility.setEDate(this,currentDate)
            DBManager.deleteAllPlants(this)
            DBManager.deleteAllStates(this)
            DBManager.deleteAllBanks(this)
            DBManager.deleteAllDesignations(this)

            val intent = Intent(this, LoginActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
            startActivity(intent)
        }
        else{
            Utility.setEDate(this,currentDate)
        }

使用此选项以共享首选项存储您的日期

fun setEDate(context: Context, eDate: String) {
            context.getSharedPreferences("", 0).edit().putString(DATE, eDate).apply()
        }

使用此代码从共享的偏好中获取日期

fun getEDate(context: Context): String? {
            return context.getSharedPreferences("", 0).getString(DATE, priviousDateDefault)
        }
相关问题