Search code examples
androidcordovaionic-frameworkhybrid-mobile-app

How to handle code when app in ionic is killed by swiping from recent activity bar


I made a hybrid app using in ionic v1 in which I have login functionality and I am storing the user data in jstorage i.e user id and password but whenever user swipes the app from the recent activity bar in Android, it remains on the same view on which it was before killing the app. I want to logout the user when i swipe or kill the app


Solution

  • Was trying some methods to log out a user when I used the following code and it worked for me.

      document.addEventListener("destory", function destoryCallback(){
          apiService.logout().then(function (callback){
            if(callback.data.data)
            {
    
            }   
            else{
    
            }     
          }).catch(function (reason) {
            // catch the reason for the failier of api   
        })
        }, false); 
    

    And also write this listener inside a device ready