I have a requirement to restart the application when the user changes a preference. Clearing the stack doesnt help me since this doesnt cancel the backend service calls. I want to kill the application process itself. I am using
Process.killProcess(Process.myPid());
and it works for me to kill the application. But what i need is to restart the application. Means kill the process and trigger a new process so the application start fresh once again.
Is there a way to do this?
Thanks in advance.
See below how to do these: Call Thread. setDefaultUncaughtExceptionHandler() in order to catch all uncaught exception, in which case uncaughtException() method will be called. "Force close" will not appear and the application will be unresponsive, which is not a quite good thing.
This is not something which one should probably attempt to do outside of a testing environment.
That said, two ideas:
1) Set an alarm for some time in the very near future and then kill your process
2) Start up something else (perhaps a small native process or shell script) that will detect your death and restart you via an intent
You could also try firing off an intent to start yourself and then dying quickly, but this sounds like a potential race condition depending on implementation. If you grabbed the binder fd out of /proc and did evil things in native code, you might be able to fire off the intent in such a way that your application crashes on the return from the ioctl...
Android is not designed to do this, and this is not a "requirement". This is an implementation. What exactly is the requirement? Why can't you design your app to handle preference changes without a restart? That seems like a very poor solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With