So I've made myself a small "incremental game".
Note: For those who are not familiar with incrementals, you click on a button and it increases a value, a currency of sorts. You buy upgrades to autogenerate this currency after you've laboriously made enough by clicking/tapping manually, saving you the cost of buy a new mouse. Or a new phone, in this case.
Now, I've been testing around with it. New to Ionic and all. I've realized that on the android (I did Ionic run android from my CLI), if I hit the native "back" button on the phone, it pauses the app completely. My autogenerating is suspended. That's fine and all! It's intended after all.
The issue/problem comes when I hit the native "home" button. Which brings me to the home screen on an android as well as when my phone auto "sleeps". Whenever either of this happens, the autogenerating continues in the background, if you already bought upgrades. Which is the opposite of the intended function. It should stop!
So, coming from native android, java. I understand there's a lifecycle to apps.
QUESTION:
How is Ionic's like? And does it go into different states depending on the method of exiting the app? Is it different between iOS and Android? I've thus far fixed it for android but I don't know how to test if it works for the iOS...
Extra info: I'm currently using $interval to keep the game's main loop running. I autogen my currency once per second as well as save it into an sqlite database right after. (Both running at once per second). Also, I have no plugins installed! Using only services.
Okay. I've sort of figured that all this has something to do with the lifecycle. From what I know using my debugging tool, I'm tracking the app doing these two, "Resume" and "Pause" by typing in my controller:
document.addEventListener("resume", function() {
console.log("Resume!");
}, false);
document.addEventListener("pause", function() {
console.log("Pause!");
}, false);
I've figured out my issue using this. So I know that regardless of method of exiting the app, I will encounter "pause" and regardless of from which method you exit the app, it passes through "resume" state on the way back in. So using this two, I simply cancel my interval when it pauses and start it up again when it resumes!
Related
I have an app I have building that is giving navigation from a location to a location. Contstantly tracking where the user is using GPS data in order to give good Directional information. Currently if a user switches from our app to another app or goes to the Android home screen, after one minute Android turns off our app for performance reasons.
I have tried using an Isolate but like flutter this gets shutdown. Next step were to use a kotlin service to handle background things but i wanted to check if anyone had done this in dart yet?
Also this is not an app that will be in the play store or on public devices. It is going on special devices that we control and are less worried about memory usage as this will be the main app ran on them.
as mentioned above in the comment by #galloper background_fetch is the thing you need, it has a method called BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); where backgroundFetchHeadlessTask is a function that will keep running even when the app is close, i used this in my app to stream location info to server.
I have an android app which is a wrapper around my mobile site. We have a site that changes everyday, and I’d like to have a method by which I can notify the user that there’s new content to be had, or just reload it programmatically.
This obviously happens when the app relaunches, but sometimes users will keep the app in sleep mode and re-open it the next day and they see a stale version of the website. Is there any way around without going native? One method I thought off was using a push notification to reload the app (i.e. use GCM to tell the app to reload the page) except I don’t want to push a new version as this would require permission changes and that would break auto-updating. I though of using socket.io for the task as I'm already using it in my app but I don’t think it'll work if the app is the background (will it? I’m an android newbie)
Thanks for any help!
When the application returns from sleep - onResume() of the activity life cycle may be invoked. If you reload the webview on this listener, that should resolve it.
Unless i am missing something very significant, this simple solution might work.
From the beginning of the APP development, I found that if I re launch the APP, the APP crashes and nothing gets displayed. I think it has something to do with the resource that is assigned to the APP and it trying to restore its previous state and it is failing to do so.
I see that, in many APPs, when it re launches the view is reset to its first screen. I would like to do the same in my APP.
Any suggestions on how I should be handling this ?
clear up memory ?
attach an event before-close and on-launch (or on-relaunch) ?
reset APP view to home screen ?
This is the first APP I am building (happens to be in Titanium). Therefore my fundamentals of APP development are weak.
Any help would be greatly appreciated.
I'm not sure what you are doing in your app, but I'm not seeing that in my Titanium apps. My users probably leave my app running/paused for days and then resume them as needed. Until their device runs out of juice, I'm pretty sure they never restart my app. Perhaps a module you are using?
There are events you can handle that will allow you to take an action when the app is put paused and when it is resumed. You can write your code to reset the app to the starting screen, which I'm partial to that idea as well. I'm not aware of a call you can make that will essentially restart your app.
The events you can handle.
Ti.App.addEventListener('pause', _.bind(this.exit, this));
Ti.App.addEventListener('close', _.bind(this.exit, this));
Ti.App.addEventListener('resume', _.bind(this.resume, this));
You would have to write the action taken when these events happen.
Code is from the https://github.com/appcelerator/Field-Service-App. This app has the hooks, but doesn't implement any actions for them. Check out the alloy.js file.
I am building an app with jQuery Mobile and Phone Gap Build and I'm unsure of the best way to implement a few security features and my attempts so far have failed. This app is aimed at iOS and Android, using Phone Gap 3.4.0 and jQuery Mobile 1.4.2.
There are 2 features I need;
First, I need the app to close/reset on app suspend. Meaning, when someone leaves the app to go to the home page, changes apps, turns off the screen, etc. the app pushes you back to the login screen. So far I have tried things like:
For Android:
document.addEventListener("pause", onPause, false);
function onPause() {
initialize();
navigator.app.exitApp();
}
For iOS in the config.xml:
<preference name="exit-on-suspend" value="true" />
This only works sometimes. When testing on Android, the app will exit when you go home or change apps, but only for the first 10 times or so, then it stops. I assume this is due to the fact that after the app is used frequently Android stops suspending it because it is actively used?
iOS testing for this feature has been limited so far.
Second, There is a bug where when you re-open the app, and you are at the login screen, the user can press the back button and revisit pages previously visited without logging in.
To remedy this I have tried clearing all auth tokens, user names, etc. (which are only stored in variables anyway) at every possible turn and it still happens.
As I stated above, I may be going about this the wrong way and there is an easier/better way to accomplish what I want.
I have a feature in my cordova app that lets user do something when user shakes the phone (I'm using shake.js for the purpose). The phone vibrates when it happens.
The problem is that, when I "alt tab" away from the app and it's in the background, the shake/vibrate combo still works. So the user might be using a completely different app and the phone would still vibrate.
Is there a way to detect that the app is in the background, or better yet, freeze the app somehow when it's going to the background?
I have this problem on Android (haven't tested it on iOS yet).
You can simply bind the pause event and you remove the shake feature from your app.
According to the documentation The (pause) event fires when an application is put into the background.
You can listen for the resume event to put back the shake feature.
As usual in the documentation you can find complete code examples.