禁用Android应用程序中的登录按钮一段时间,然后从服务器中抽出时间



我想禁用应用程序中的一个按钮,以便没有人可以登录和GPS位置。我当时正在使用此代码,它进入了无限循环,现在它没有记录

private void logoutWebService(String systemId, String imei, String lat, String lng) {
    AppPreference preferences = AppPreference.getInstance(Dashboard.this);
    String distanceValue = preferences.getString(PrefConstant.ODOMETER, "");
    //
    SharedPreferences prefs = this.getSharedPreferences("time", Context.MODE_PRIVATE);
    long previousTime = prefs.getLong("time", 0);
    long currentTime = new Date().getTime();
    // 30*60*1000 - 30 min, each with 60 sec, each with 1000 millisec
    if (LoginActivity.logintime - currentTime > 2*60*1000){
        //enable the button
        Logout logoutStatus = new Logout(HttpConstant.LOGOUT_URL + "SYSID=" + systemId + "&IMEI=" + imei + "&DATETIME=" + AppUtility.dateTime() + "&LAT=" + lat + "&LNG=" + lng + "&ODOMETER=" + distanceValue);
        Logout.setEnabled(true);
        logoutStatus.setProgressEnable(true);
        HttpConnectionUtil.callWebService(logoutStatus, this, WebserviceType.LOGOUT, mLogoutWebServiceCompleteListener);System.out.println("Logout .... " + logoutStatus.URL.toString());
    } else
    {
        SharedPreferences.Editor editor = prefs.edit();
        editor.putLong("time", currentTime);
        editor.apply();
        signOut.setEnabled(false);
        //disable it and start a new CountdownTimer; this is needed in order for
        //it to to become enabled if you're still in the app and the time ran out
        signOut.setEnabled(false);

尝试以下:

private interface ResponseListener {
     void onSuccess();
     void onError();
}
public void sendLocation(Location location) {
    logoutButton.setEnabled(false);
    webService.yourCall(location, new ResponseListener() {
        @Override
        public void onSuccess {
            logoutButton.setEnabled(true);
        }
        @Override
        public void onError {
            logoutButton.setEnabled(true);
        }
     });
}

您必须在服务电话中添加回调。在您的情况下,这在您的httpconnectionutils课内。为了给您一个提示,您必须如何向我展示Utils类的代码...

相关内容

最新更新