【问题标题】:How to set session timeout for my android application when using server使用服务器时如何为我的android应用程序设置会话超时
【发布时间】:2017-09-18 08:59:02
【问题描述】:

我正在编写一个 Android 应用程序,我正在尝试登录系统, 但是Loading Dialog Tack 很多时候就消失了 虽然系统已经完成了Login 过程。 如何设置登录过程的会话超时?

谢谢。

【问题讨论】:

    标签: android session timeout


    【解决方案1】:

    试试这个。

    在您的代码中设置超时。

    HttpURLConnection

    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    // edit here ,change time
    connection.setConnectTimeout(20000);
    connection.setReadTimeout(20000);
    

    OKHttp

    private final OkHttpClient client;
    
    public ConfigureTimeouts() throws Exception {
        client = new OkHttpClient.Builder()
            .connectTimeout(100, TimeUnit.SECONDS)
            .writeTimeout(100, TimeUnit.SECONDS)
            .readTimeout(100, TimeUnit.SECONDS)
            .build();
    } 
    

    【讨论】:

      【解决方案2】:

      正如this post 应用它。你可以试试这个:

      public void timerDelayRemoveDialog(long time, final Dialog d){
          new Handler().postDelayed(new Runnable() {
              public void run() {                
                  d.dismiss();         
              }
          }, time); 
      }
      

      【讨论】:

        【解决方案3】:

        创建一个 andler 并关闭 post 延迟方法中的对话框。

         new Handler().postDelayed(new Runnable() {
            public void run() {                
                dialog_obj.dismiss();         
            }
        }, 6000); 
        

        此代码将在 6 秒后关闭对话框。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-11-04
          • 1970-01-01
          • 2011-02-23
          • 2014-12-15
          • 1970-01-01
          • 2021-12-28
          • 1970-01-01
          • 2017-01-30
          相关资源
          最近更新 更多