Exit app in android (solved)
-
Hello, I’m trying to exit my app this way:
can you tell me what’s wrong?
When the user press a button I run this action and the code in the else block is executedlogout({ commit, dispatch }) { if (navigator.app) { navigator.app.exitApp(); } else if (navigator.device) { navigator.device.exitApp(); } else { commit('API_TOKEN', undefined); dispatch('setLoginData', undefined); dispatch('setHijoActivo', undefined); window.close(); } },
-
@jpsala you probably don’t have navigator available from where you called that logout action of yours.
-
@metalsadman, do you have some advice? how is that navigator is not available? maybe because I’m not in a .vue file? did you have to exit from an android app?
-
it works find in the emulator but not from the actual device once installed
-
@jpsala yep, i guess that resides in your action something js. try using mapActions in your vue into that file, see if it gets navigator context, otherwise you’ll have to transfer that logic in your view. or you could pass the navigator itself as payload to your action.
ie.// in your vue file this.$store.dispatch('logout', navigator) // in your action logout({ commit, dispatch }, navigator) { ...
-
it’s strange that it’s working in the emulator but you are right, I’ll try to refactor so to use the navigator object after returning from the action, or something like that
-
@jpsala said in Exit app in android:
it’s strange that it’s working in the emulator but you are right, I’ll try to refactor so to use the navigator object after returning from the action, or something like that
see update above.
-
mmm, nice one
easier that what I was going to do, I’ll try that, thanks man!
-
@metalsadman, it worked!!! I suppose it worked outside a .vue because of the window.close(), sending navigator as a param to the action worked like a charm, thanks again!