0

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

Aniket Pharale
  • 21
  • 1
  • 1
  • 8

2 Answers2

0

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
}
Piwnik
  • 181
  • 1
  • 5
  • Welcome to Stack Overflow. Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. [How to Answer](https://stackoverflow.com/help/how-to-answer). Thank you. – Elletlar Feb 05 '19 at 15:17
  • I tried the same but of no use, because whenever user minimizes the app he goes in the pause event and when a user comes back the app then he goes in to resume mode. I can't log out user when user minimize the app – Aniket Pharale Feb 06 '19 at 11:27
  • Check this one https://stackoverflow.com/questions/19568315/how-to-handle-code-when-app-is-killed-by-swiping-in-android – Piwnik Feb 06 '19 at 11:37
0

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

Aniket Pharale
  • 21
  • 1
  • 1
  • 8