2017-03-02 78 views
0

我已经尝试了所有类似的问题在stackoverflow,但仍然没有给我正确的答案(就像我在找什么)。在android上创建会话并在特定时间破坏会话

我尝试在一天内创建一个会话。会话将在特定时间内销毁

private void notifyPopUpWhen24Hours(){ 
     Calendar firingCal= Calendar.getInstance(); 
     Calendar currentCal = Calendar.getInstance(); 

     firingCal.set(Calendar.HOUR, 8); // At the hour you wanna fire 
     firingCal.set(Calendar.MINUTE, 0); // Particular minute 
     firingCal.set(Calendar.SECOND, 0); // particular second 

     Date currentDates = currentCal.getTime(); 


     if(currentDates.before(firingCal.getTime())){ 
      //do simething 
      // the session still on 
     }else{ 
      // If the current date is after the firingCal.getTime, then sesion destroy 
     } 

    } 

在上面的代码中,我尝试在早上每8.00次销毁会话。 但上面的代码并没有给我所寻找的。

我的问题,如何创建会话并在特定的时间销毁它。谢谢。

回答