I have a problem, users report that when the application shuts down (ending the process), the app restarts and user must shuts it down again and the app restarts again. Sometimes even 4x ...
How is it possible? I will close all the services & activities that have been started and I will terminate the whole process ...
I've noticed that only users with android 7 report it to me. It's never happened to me (android 5).
It is the same restart as if the activity is an error, just an exception and a restart. But Fabric.io tool has no record of any errors ... so I do not know what could happen, does anyone have any idea?
Add a Log.d statement into your onCreate in the Application class.
Extent the application class
public class TheApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Log.d("restart", "My App is restarting");
}
}
and in the manifest
android:name=".TheApplication" <-- make sure the package is correct.
Install the app adb install yourapp.apk
open a terminal
adb logcat restart *:S
then click on your app and watch the terminal.
This way you don't have to run it in debug mode and it runs like a regular app.
If you see it logging the app restarting several times maybe you can put in a trace in places (loging) like put one in the onDestroy of the main launcher class.
hope you figure it out.
It could happen from the 3rd party library that you includes into the project.
Some of them might have a service to trigger something intervally and that wake up the app the couple times.
This issue happened before on the app that i've been working on where the app keep waking up after that particular library get included.
Please check for any service that running in the background.
Related
How can an apps application class run at once the device starts?
Hello,
I have an application where the application class is running it's onCreate, but no activites on device startup. And i don't mean when the BOOT broadcast is sent, i mean at once the device is started.
I can see this since i've added file logging to the appliation class, but i cannot see that it comes any further (into any activities).
My manifest has
No receivers
No services with their own process id
Is there anything else that could start my application class on device start?
When i click and start the application on my device, i see logs in the application class again, but this time it has another process id than it had.
Thanks in advance!
===================
ok, so after commenting out all obvious code and manifest entries, i finally set my Sync Adapter Service to enabled=false, and then the problem did not occur. Is this normal behaviour of a sync adapter service?
On a particular (low-end) Android phone (running Android 5.1) one of my app's services will fail to start, when this happens logcat has the following lines:
D/nzy ( 1499): shouldBlock from:<package name>, ComponentInfo{<service name>}elapsed:21270
D/nzy ( 1499): ===ignore ==ComponentInfo{<service name>}
D/zlg ( 1499): startService ===ignore ==ComponentInfo{<service name>}
I'm not clear as to the exact circumstances when the service fails to start. Although it does seem to be consistent that when I install the app from fresh the service is started, but if I then manually do a "Force Stop" of the the app and then restart it, the service will not be started, with the above output in logcat.
What do nzy and zlg refer to?
How can I prevent this from happening?
In android 4.4 and below, who loads a native application (/system/bin/*) at startup, I think that the file init.rc is responsible, it is correct?
Then if a native application crashes (for example /system/bin/mediaserver) it restart automatically, then the question is: who is responsible for the application restart? there is a file?
ActivityManagerService restarts the native apps.
There's usually some chatter in logcat when an app is restarted by the activity manager service, in the normal log and/or event log
(logcat -b events).
More Info:
If you see the code of ActivityManagerService.finishForceStopPackageLocked() method, this method fires an Intent with action Intent.ACTION_PACKAGE_RESTARTED.
And it is called from various methods like:
ActivityManagerService.forceStopPackage()
IPackageDataObserveronRemoveCompleted.onRemoveCompleted()
So internally there's an PackageDataObserver implemented in ActivityManagerService, which observes if any package is removed, and if it's need to be restarted, an intent is fired with the action Intent.ACTION_PACKAGE_RESTARTED
And every package is forced closed using ActivityManagerService.forceStopPackage(), it knows which package to restart.
Hope it clears the doubt.
This question already has answers here:
Listen to own application uninstall event on Android
(3 answers)
Closed 7 years ago.
Recently i've seen a funny app - Photo Wonder.
When this app is uninstalled, it shows a web survey page asking for the reason of app uninstall. Now, here is the problem.
As far as I know, after an app has been removed, the system broadcasts ACTION_PAKAGE_REMOVED intent.
But this funny app was able to show my the web page although the official doc says
"The package that is being installed does not receive this Intent."
Anyhow, I could find a process checking some kind of status of the app.
Now here is the question. Can the native app catch the broadcasted intent from android system?
If it is possible, please let me know how! :-(
I believe I've got the main idea of how they did it. Here is the pieces of the puzzle.
Any Android application can start a process by calling Runtime.exec() function.
Runtime.getRuntime().exec("chmod 755 '/data/data/my.app/files'/native_code");
After this line of code gets executed there is another process spawned. This process runs under the same linux user as the application itself.
When a user opens Settings -> Apps -> My App and presses "Force stop" button, main application process gets killed, but the process hosting native program (see above) still runs. I personally believe this is a security issue and I am going to report it back to AOSP.
Such native program can run infinitely and do nothing - just sleeping. But before going to sleep, it registers a termination signal handler which will be called when process is about to be terminated by the system.
int main(void) {
signal(SIGTERM, termination_handler);
while(1) {
sleep(10);
}
}
void termination_handler(int sig) {
// handle termination signal here
}
Now you should already know what the last piece is, right? My native termination_handler should be able to launch a browser. I didn't try this in code, but I assume this is possible, because I can do it using adb shell as following
adb shell am start -a android.intent.action.VIEW -d http://www.google.com
Now back to the question about how Dolphin Browser does it. Install the app and launch it at least once. Once started, it registers a native uninstall watcher using the principles described above. To see it, connect to the device and open adb shell. Then call ps to see list of processes. You will see two processes similar to following
u0_a109 315 ... mobi.mgeek.TunnyBrowser
u0_a109 371 ... /data/data/mobi.mgeek.TunnyBrowser/files/watch_server
As you can see it starts a watch_server native program, which is a part of its apk-file. Now open App info page of Dolphin Browser and press "Force Stop". Switch back to terminal and call ps again. You will see there is no mobi.mgeek.TunnyBrowser process anymore, but watch_server still runs.
By the way this approach will only work, if watcher server runs all the time. To
make sure it is always up, both apps require "run at startup"
permission, where they start their watchers.
Now, when you uninstall the app, Android stops all processes belonging to this application. Watcher receives termination signal and opens browser with predefined URL and then shuts down.
I might look a bit different in some details, but the main concept behind this hack must be as described.
There could be a tricky thing like that application is also having watcher service.
You can check the permission used by that app may contain INSTALL and UNINSTALL permissions.
HOW IT WORKS:
instead of single app that may have 2 app bundle.
as and when you install it, this app is also installing some service that is watching your app status
When you try to uninstall that app the system broadcast is called which is handled by that service and will check that if your package is exist in installed application or not.
as soon as this service finds that your package is not in the list it calls an intent with action view with the web url to open the brawser.
My application throws an error when I attempt to start it from "Recent applications". Problems :
Error appears only if application was inactive (stopped) for a long time (approximately one hour). I can't catch this error by myself - when I'm killing process by myself and then relaunched it there is no errors!
I can't see Exception log in debugger, since it's disconnects after so long time.
How can I catch such kind of errors in debugger? Looks error appears only when OS kills application by itself.
EDIT
I didn't overrided onResume method. Just onStart, and there is nothing special except instantination of my SQLiteOpenHelper.
even if your app is in paused/stopped state, log cat will still be working as long as device is connected. make sure you selected all logs options in windows > devices > all logs instead of windows > devices > com.your.project .
so when you will try to relaunch crash must be recorded in logCat
if still have any issue, install logcat app from market and refer it for logs.
Sounds like there might be an issue in your
OnResume
call. What is your application doing? Is it using a location manager? Does it have services or threads that need to be restarted? More infomation please.
Look through the Android application lifecycle chart:
http://developer.android.com/reference/android/app/Activity.html
It should help you understand what's going on. If all else fails, add a lot of logging to logcat and see what the output looks like on your end. As long as you don't unplug the device, you shouldn't lose that in Eclipse. If you do, you can always run "adb logcat" from the command line or shell to see exactly what's happening.