I am making an android app on API 15 for a mobile computer application.
In this app I have a background service, a lot of classes inheriting from AsyncTask, and some sql updates and broadcasting to the service on the app pausing.
I have recently discovered an issue where going to a specific screen in my app, hitting the home button, bringing up my app list, and swiping away my app to kill it results in the app closing and then soon restarting itself at the main activity. It should just close normally.
I have tried placing breakpoints everywhere, and even disabling the background service, but i cannot seem to find any indication of what is restarting the app when it is closed.
I just tried getReferrer inside a try catch and my app says it isnt responding and shuts down even though its in a try catch block.
Both problem seem odd to me.
If it means anything, Android studio will still be debugging the app once it has opened again after i close it.
If anyone could shed some light on what could be restarting my app after i close it, it would be very helpful.
EDIT:
I am using Start_Not_Sticky. this and Start_Redeliver_Intent are ideal option from what i have read.
Thank you to Kevin Krumwiede for suggesting grepping all my code for the main activity's name. I had no idea I could go through all of the code in my project within the IDE instead of going one file at a time.
I had previously tried going through all my classes and searching each individually for reference to it with ctrl+f but i never considered looking in one of my activities that i hadn't modified in months for the new issue.
when I used ctrl+shift+f it all came together as i saw the startActivity function inside of OnDestroy(), not sure how i never noticed this issue before.
Related
Recently I noticed one thing in my app.
I created apk for my app say ABC.apk and copied to my device and installed it by clicking on it. After the installation got successfully completed, I got 2 options 'Done' and 'Open', the usual options we get after installation.
I clicked on 'Open' and run the app. I moved to some screen and I minimized the app and moved to someother app, when I click my ABC, it started from my first screen.
It was just fraction of seconds I moved back to it, hence it should not be killed though launched it like it is first time.
Few things I noticed I if I explicitly killed this first instance from background running apps and start the app again it is not giving me this problem, same if I click 'Done' instead of 'Open' it works fine.
Is there anyone who are facing same issue, or have some solution for it?
Thanks in advance.
Prajakta
The problem is the way that the app gets launched from the installer doesn't exactly match the way Android launches apps from the HOME screen. Because this, if you initially launch your app from the installer, when you then later launch the app again from the HOME screen, Android doesn't recognize that the app is already running and just creates a new instance of the root Activity and adds it to the existing task on top of whatever activities are already there.
This is why, if you kill the app and start it again from the HOME screen, you won't ever see this strange behaviour.
This is a nasty Android bug which has been around since the dawn of time and is still broken, even though countless issues have been opened about it and the behaviour is reproducible and well-documented.
See the following issues and questions:
https://issuetracker.google.com/issues/36941942
https://issuetracker.google.com/issues/36907463
https://issuetracker.google.com/issues/64108432
App restarts rather than resumes
Re-launch of Activity on Home button, but...only the first time
There is a workaround documented in my answer to
Re-launch of Activity on Home button, but...only the first time
Just some general comments that come to mind that you must consider that can cause problems.
If you are trying to deploy an apk, did you switch from debug to release before building it? Make sure you are doing a full release. Do a clean and rebuild while in release mode as well.
Did you sign the apk?
Make sure all the necessary (if any) permissions are set in the manifest that will be needed by your app, on the device.
Hope these help point you in a direction.
Mike
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?
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.
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.
I've written an application for Android, but it doesn't close and it also starts automatically with the system. I don't know why, but it can't be closed, even through the Task Manager. So I would like to know why it doesn't close.
I'm sure you have read how Android apps aren't really supposed to close. That aside, I also needed my app to terminate when no longer visible. First I tried
System.exit();
That worked just fine but it isn't the proper way to do it, the best way is to call
finish();
I'm sorry if you had already tried/were aware of those solutions; it wasn't clear from your question.