Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile programmatically reinitialise/restart app

I am writing an app with phonegap and jquery mobile.

For handling unknown errors I need to completely restart my app and reinitialise all variables and dynamic content back to being the equivalent of the first run.

Originally I was just using $.mobile.changePage($'#home') which obviously doesn't work because it doesn't reinitialise any of the dynamic content or variables so I end up with double ups.

Is there a method I can call in jquery mobile to completely restart the app and set everything back to the initial settings?

like image 540
Jamesla Avatar asked Sep 09 '13 22:09

Jamesla


3 Answers

For a full solution, I think you are out of luck.

iOS definitely will *NOT allow the programatic killing of an app, let alone the programatic starting one.

Android does allow the killing of an app. Though undocumented (that I could find) you can use

navigator.app.exitApp();

to kill the current app.

However, you still cant re-start it programaticly.

I think your best bet will be to write the code to reset the variables and local storage/DB (if used). Then reload the index page via document.location.href = 'index.html?var=xxx'; where xxx = the current timestamp. Placing the timestamp at the end will ensure that it pulls a non-cached version of the page.

*Edit: Added not to my statement about Apple allowing app killing as it should have been.

like image 127
Dom Avatar answered Nov 01 '22 20:11

Dom


Try, document.location.href

document.location.href = 'index.html';
like image 20
Robin C Samuel Avatar answered Nov 01 '22 19:11

Robin C Samuel


Have you tried to reload app?

The reload() method is used to reload the current document.
The reload() method does the same as the reload button in your browser.
By default, the reload() method reloads from the cache, but by you can force the the reload to get the page from server by setting the forceGet parameter to true.

location.reload();
like image 2
Serge P Avatar answered Nov 01 '22 19:11

Serge P