0

my application sometimes shows a forceclose alert. bt after forceclose button the application is not fully closed. Is there any way to listen this forceclose event, so i can redirect to app login page.

bolt123
  • 39
  • 1
  • 12
  • 2
    Wouldn't it be better to fix your code so it doesn't show the Force Close alert dialog? – Squonk Dec 28 '13 at 09:39
  • Do you mean the Application Not Responding (ANR) dialog? Which has a Force Close option. Or just the usual unhandled runtime exception "Unfortunately app has closed"? – laalto Dec 28 '13 at 09:40
  • if your problem is ANR the this [link](http://developer.android.com/training/articles/perf-anr.html) may be useful – Mitul Gedeeya Dec 28 '13 at 09:42
  • Stop writing code that makes your app un-responsive to user, so user doesn't have to force close it. – S.D. Dec 28 '13 at 09:42
  • "Unfortunately app has closed". Yes it is better fix code. but somewhere in code have problem, that is why i search for this option? – bolt123 Dec 28 '13 at 09:50
  • possible duplicate of [Android UncaughtExceptionHandler that instantiates an AlertDialog breaks](http://stackoverflow.com/questions/5519347/android-uncaughtexceptionhandler-that-instantiates-an-alertdialog-breaks) – Hamad Dec 28 '13 at 19:16

1 Answers1

1

The force close screen is an Android default display that indicates that an error or exception occured in your code that wasn't handled: you can't override it, and the only way to prevent it is to figure out and then actually handle the exception that occured in your code.

If you need help debugging to determine what the actual exception or error was take a look at the debugging guide.

There is a way to set a global exception handler, which will catch any exception which is caused on that thread. So you set it in your main activity and it will apply to every subactivity.

final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        // get the crash info
        defaultHandler.uncaughtException(thread, ex);
    }
});

enter image description here

Shyam
  • 6,376
  • 1
  • 24
  • 38