0

I have an app that loads a web page, in WebView. Once I've opened my app, if I hit the back button at any point it causes a Force Close. Has anyone run into this? I'm not sure what I really want. I'd like to disable the back button since my app has "Back" built into it. But leaving it with the default "Back to the previous page" functionality would be fine as well.

11-29 18:54:53.393: DEBUG/MediaScannerService(254): done scanning volume external
11-29 18:54:54.403: INFO/InputReader(62): Device reconfigured: id=0x0, name=qwerty, display size is now 320x480
11-29 18:54:54.403: WARN/InputReader(62):   Touch device did not report support for X or Y axis!
11-29 18:54:59.453: INFO/ARMAssembler(62): generated scanline__00000077:03515104_00001004_00000000 [ 65 ipp] (85 ins) at [0x439e0520:0x439e0674] in 5501712 ns
11-29 18:54:59.493: INFO/ARMAssembler(62): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x439e0678:0x439e0840] in 1081228 ns
11-29 18:54:59.653: INFO/ARMAssembler(62): generated scanline__00000177:03515104_00001002_00000000 [ 87 ipp] (110 ins) at [0x439e0848:0x439e0a00] in 610063 ns
11-29 18:55:03.283: WARN/KeyCharacterMap(286): No keyboard for id 0
11-29 18:55:03.283: WARN/KeyCharacterMap(286): Using default keymap: /system/usr/keychars/qwerty.kcm.bin

Each time I click Back the LogCat gives me this:

11-29 18:55:17.303: INFO/InputDispatcher(62): Application is not responding: AppWindowToken{406f1558 token=HistoryRecord{406e7948 com.mysite/.MySite}} - Window{406d90f0 com.mysite/com.mysite.MySite paused=false}.  5026.2ms since event, 5023.1ms since wait started
11-29 18:55:17.303: INFO/WindowManager(62): Input event dispatching timed out sending to com.mysite/com.mysite.MySite

Note that with the emulator the app doesn't crash like it does on my tablet.

Ben
  • 60,438
  • 111
  • 314
  • 488
  • 3
    Please post the logcat stack trace which will show the exception – skynet Nov 27 '11 at 18:48
  • Please post the log error, in the logcat. Ah, I see I'm not the only one asking for that... – davidcesarino Nov 27 '11 at 18:50
  • 1
    As the others say, please post your error from Logcat. Also, a word of caution - people expect the back button to go back - if that stops working, some people will think there's a bug in your application. Instead of disabling the back button, why not give it the same functionality as your built-in back button? – Michell Bak Nov 27 '11 at 18:53
  • 1
    True, just disabling the back button is definitely a very bad practice. You should override it with a similar "back" behavior (back to previous page), but you should not just disable it. – davidcesarino Nov 27 '11 at 18:58
  • 1
    When you look at the logcat you will probably see that you are referring to something that no long is set after the back button is pressed. – James Black Nov 27 '11 at 19:03
  • logcat please. your question has no meening without it.You should know... – weakwire Nov 28 '11 at 03:38
  • It seems that you are getting an [ANR-dialog](http://developer.android.com/guide/practices/design/responsiveness.html), not a Force-Close-dialog. This means you block the UI-thread for 5 seconds. Since this happens when you press back I'd say you do expensive stuff (network calls, processing huge files, ...) inside the one of the later parts of the activity lifecycle within the UI thread. Can you post your `onPause()`, `onStop()` and `onDestroy()` methods? You can also try to diagnose the problem with [strict mode](http://developer.android.com/reference/android/os/StrictMode.html). –  Nov 30 '11 at 10:50
  • I don't have any of those methods... my site only loads a website in a `WebView`. Aside from that, the app does nothing. I have only specified an `onCreate` and `onKeyDown` function – Ben Dec 01 '11 at 00:09

1 Answers1

1

Use the following to finish your activity when the back button is pressed. Of course, something else could be causing the force close, but it is hard to tell without the LogCat output:

   @Override
   public void onBackPressed() {
      this.finish();
      return;
   }
Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • What's the point? You override the default implementation, which just calls `finish()`, with your own implementation, which also just calls `finish()`. Check [the activity source](http://google.com/codesearch#uX1GffpyOZk/core/java/android/app/Activity.java&q=activity%20package:android&type=cs&l=1919) for reference. –  Nov 30 '11 at 00:08
  • I know that. But apparently leaving it to the default implementation was causing his app to force close. Seeing as he hasn't responded to this saying that it still force closes, I guess it worked. – Raghav Sood Nov 30 '11 at 08:28
  • That's a pretty wild guess given that your answer is 2 days old and the OP edited new infos to solve the problem into his question 11 hours ago. If this would have worked, it would be marked as the correct answer. Also I don't see how this *can* work under any circumstances. Every programming problem has a logical explanation. If you can explain what exactly the problem is here and why this solves it: Go ahead I'm listening, I make mistakes and don't see things. I'm willing to learn. But if you can't do that: Please don't guess around and blame working apps on black magic like this. –  Nov 30 '11 at 11:17