I started developing an app with Kivy for Android and managed to build and run an APK today.
Couldn't find a straight answer on how to handle my app being suspended and resumed by a user without going through the initialization/loading screen? Is there a special mechanism that will handle this?
It is rather annoying that every time I send the app to the background and bring focus back to it there is that loading screen popping up.
I have never used Kivy or developed for android, but I was able to find:
This
From the link:
If you just want your app to not be closed completely (so that it doesn't restart entirely with the splash screen etc. every time), you just have to add an on_pause method to your App class, and it should return True. You can also do any pre-pause stuff in this method. However, the app doesn't really keep running, it just keeps memory state.
If you want it to do computations in the background you can use Python-for-android.
Kivy has an on_pause and on_resume methods that you can use to handle these events. These are methods of the main App class that are called automatically for you.
Related
I am using Robotium for testing android applications and am interested in how to detect a situation when an external application activity (e.g. browser, camera, facebook) is being launched by tested app. There are several questions asking how to handle such situation, but all I need is to detect it, for example just log time when it's occurred. Is this possible using Robotium or simple Instrumentation?
BTW, I can't use the solution when system apps are being replaced by fake analogues, I can't even know what application (and when) will be launched, because the tests are random. (Yes, I know, it's a bad approach, but this is a project restriction).
See my answer here. The main idea is to detect current top Activity, which is Activity of external application. You can create Service, which will monitor top activities.
Anther way is to check when your activity looses focus. When it looses focus that means that the other external Activity has focus instead.
http://developer.android.com/reference/android/app/Activity.html#hasWindowFocus()
You can use Solo.waitForCondition() in conjunction with hasWindowFocus.
So without altering the Java activity code (as many posts here suggest), is it possible to fully exit (kill) an app instead of just putting it on hold in the background?
With Cordova 3 & Android, if we want to "pause" an app we call;
navigator.app.exitApp();
But as said, this is just pausing it.
Tha java solutions proposed to edit the main activity and set;
super.setBooleanProperty("keepRunning", false);
But again, this prevents your app from going to background all the time (not when you want to).
Some even suggested driving your app to crash thus force exit!
Another issue, Android discourages killing apps. The same thing with Apple iOS and their iOS Human Interface Guidelines stating; Never quit an iOS app programmatically. People tend to interpret this as a crash.
So again; How to peacefully kill my app to free space/reset?
On calling back my first activity ,it should call onResume.It is calling the same in android version 2.2.But when I checked in for android 4.1 it is calling onCreate method that calls splashscreen and hence it looks like the app is restarting.How could I make sure that onResume is called for every version of android?
Thanks
As Henry said, you can't guarantee that onCreate won't get called again - you're not in charge of that lifecycle. If the system decides to get rid of your activity while it isn't in the foreground, then when you return to it it will be recreated. If you want to make sure that you don't show the splash screen again you will need to save state to say that it has been shown (e.g. using onSaveInstanceState). As an aside, splash screens generally aren't a great idea on android, partly for this reason. It's better to view your app as a loose collection of activities that can be entered and reentered somewhat randomly, as the android system basically does. Where you see splash screens used on android, it's common to see them slightly misbehave.
If you want to keep track of your application lifecycle, to which a splash screen might correspond, then you can subclass the Application object and put a flag there. However, android may leave your app running for weeks, so the user won't necessarily see that splash screen very often.
Keep in mind that the true purpose of a splash screen is supposed to be to show the user something nice while a long loading process is happening, and not to put your branding in their face. If you use the approach with onSaveInstanceState (and often onRetainNonConfigurationInstance too) then the cases where you show the splash screen would indeed be those where you need to redo that loading process, so that would be correct. However, it's generally better to rethink the design and bring up a minimal UI quickly, then show that some data is loading.
Finally, here's someone who goes into great depth on this subject: http://android.cyrilmottier.com/?p=632
If the system has removed your activity while it was unused, it will receive an onCreate thats normal behavior.
You could make the splash screen part of a separate activity to avoid the problem.
Is there any way to programmatically pause an Android app in Phonegap? I would like to mimic the behavior that occurs when you hit the HOME button. I've already had to overwrite the back button handler using this, and while in most cases I want it to do my action, when in a particular state the user would expect the app to minimize, and I want to replicate this behavior.
Keep in mind, on Android this is not the same as closing the app. That is quite easy to do with device.exitApp(); but I would like it to remember its state and keep running in the background. Especially if there's still an asynchronous job being done in the background.
Is there a feature in Phonegap to achieve this?
Possible duplicate of Manually pause an application in Android Phonegap, but I couldn't find some of the tools the OP mentioned there such as navigator, so I was nervious to totally edit and rewrite their post
The simple answer appears to be: no.
However, for anyone else that comes down this path, its not impossible. It's just that there isn't a feature of Phonegap to do it for you.
The Android equivalent of "sleeping an app" is actually just opening another intent. Specifically, opening the "Home" intent would sleep the running app and bring you back to the home screen. But as far as I can tell from asking around and scoping the docs, Phonegap doesn't have a direct way of opening intents.
What you (supposedly) can do is one of two things:
This plugin is supposed to be promising
Call the Java code that does it yourself using the means described here
Mind you, as of right now I've decided to not go any further with this, so I make no promises about either of those means, having not attempted them myself.
I invite anyone else who decides to pursue this further to update their experience here.
During testing of mgwt application in emulator, if we suddenly stop and go to home page in emulator and start the application again, it will directly load the last page where we were wokring. Why it is not resetting it to the first page?
In GWT on module function, I am always loading the default place. I need to explicitly go and remove data and then start application to proceed.
How to overcome this problem programatically? Do we have any reference for it? I have not used gwt-phonegap, it is just mgwt with GWTp framework application.
I think your application isn't stopped. I think it is running in background. If you bring it back to front, it shows the same screen again.