简体   繁体   中英

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 ie 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

You can listen to pause or resume events and logout on one of them.

 document.addEventListener("pause", onPause, false); function onPause() { // Handle the pause event } 

or

 document.addEventListener("resume", onResume, false); function onResume() { // Handle the resume event } 

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM