CountdownTimer导致崩溃

时间:2012-10-29 11:03:35

标签: android android-progressbar countdowntimer android-homebutton

当我按下主页按钮并离开我的应用程序时,我的CountdownTimer会导致Android操作系统崩溃。 每个手机和每个版本的Android都不会发生这种情况。 Logcat中没有显示异常。 这是我的代码:

    ProgressBar progressbar = (ProgressBar) findViewById(R.id.progressbar1);
    progressbar.setMax(100000);  

    /* ------------- BEGINNING: CountDown */

    final TextView myCounter = (TextView)findViewById(R.id.mycounter);
    counter = new CountDownTimer(100000, 1000) {  

    @Override
    public void onFinish() {  

    final Dialog dialog = new Dialog(zeitspiel.this);
    dialog.setContentView(R.layout.dialog_zeitspiel);
    dialog.setCancelable(false);
    dialog.setTitle("Dialog");

    /* More stuff regarding the dialog... */

    dialog.show();  
    myCounter.setText("Ende!");

    }

    @Override
    public void onTick(long millisUntilFinished) {

    myCounter.setText("Verbleibende Zeit: " + String.valueOf(millisUntilFinished / 1000) + " Sek.");
    pBarCounter = (int)millisUntilFinished;
    }

   }.start();  
   /* ------------- ENDING CountDown */

   /* ------------- BEGINNING: Progressbar */
   new Thread(new Runnable() {
   public void run() {
   ProgressBar progressbar1 = (ProgressBar)findViewById(R.id.progressbar1);

   while(pBarCounter <= 100000){  
   progressbar1.setProgress(pBarCounter);
   }
   } }).start();
   /* ------------- ENDING of Progressbar */

我试图禁用主键以“解决”问题 - 它工作正常,但问题是Android 4.x不支持此解决方案并导致异常。所以这种溶解是不可行的。

   @Override
   public void onAttachedToWindow() {
   this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
   super.onAttachedToWindow();
   }

logcat的:

09-17 16:19:45.466: I/ActivityManager(272): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=de.toropi.test.plus/.MainActivity bnds=[160,150][240,250]} from pid 482
09-17 16:19:45.546: D/dalvikvm(2115): Late-enabling CheckJNI
09-17 16:19:45.546: I/ActivityManager(272): Start proc de.toropi.test.plus for activity de.toropi.test.plus/.MainActivity: pid=2115 uid=10027 gids={}
09-17 16:19:45.596: W/ResourceType(272): Skipping entry 0x7f04002a in package table 0 because it is not complex!
09-17 16:19:45.596: W/ResourceType(272): Skipping entry 0x7f04003d in package table 0 because it is not complex!
09-17 16:19:45.666: D/TextLayoutCache(2115): Using debug level: 0 - Debug Enabled: 0
09-17 16:19:45.716: D/libEGL(2115): loaded /system/lib/egl/libGLES_android.so
09-17 16:19:45.716: D/libEGL(2115): loaded /system/lib/egl/libEGL_adreno200.so
09-17 16:19:45.716: D/libEGL(2115): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
09-17 16:19:45.726: D/libEGL(2115): loaded /system/lib/egl/libGLESv2_adreno200.so
09-17 16:19:45.756: D/OpenGLRenderer(2115): Enabling debug mode 0
09-17 16:19:45.866: I/ActivityManager(272): Displayed de.toropi.test.plus/.MainActivity: +330ms
09-17 16:19:47.656: I/ActivityManager(272): START {cmp=de.toropi.test.plus/.hauptmenue} from pid 2115
09-17 16:19:47.706: D/dalvikvm(2115): GC_FOR_ALLOC freed 153K, 4% free 6525K/6791K, paused 16ms
09-17 16:19:47.716: I/dalvikvm-heap(2115): Grow heap (frag case) to 6.794MB for 371216-byte allocation
09-17 16:19:47.746: D/dalvikvm(2115): GC_FOR_ALLOC freed 1K, 5% free 6886K/7175K, paused 14ms
09-17 16:19:48.116: D/dalvikvm(2115): GC_CONCURRENT freed 567K, 10% free 6730K/7431K, paused 297ms+1ms
09-17 16:19:48.206: D/dalvikvm(2115): GC_CONCURRENT freed 342K, 8% free 6877K/7431K, paused 1ms+2ms
09-17 16:19:48.296: D/dalvikvm(2115): GC_CONCURRENT freed 389K, 7% free 6940K/7431K, paused 1ms+2ms
09-17 16:19:48.476: I/ActivityManager(272): Displayed de.toropi.test.plus/.hauptmenue: +810ms
09-17 16:19:48.486: D/OpenGLRenderer(2115): Flushing caches (mode 0)
09-17 16:19:50.286: I/ActivityManager(272): START {cmp=de.toropi.test.plus/.allgemeinwissen} from pid 2115
09-17 16:19:50.486: D/dalvikvm(2115): GC_CONCURRENT freed 240K, 5% free 7134K/7495K, paused 2ms+3ms
09-17 16:19:50.555: I/ActivityManager(272): Displayed de.toropi.test.plus/.allgemeinwissen: +236ms
09-17 16:19:50.566: D/OpenGLRenderer(2115): Flushing caches (mode 0)
09-17 16:19:52.246: I/ActivityManager(272): START {cmp=de.toropi.test.plus/.allgemeinwissen_pro} from pid 2115
09-17 16:19:52.686: I/ActivityManager(272): Displayed de.toropi.test.plus/.allgemeinwissen_pro: +423ms
09-17 16:19:52.696: D/OpenGLRenderer(2115): Flushing caches (mode 0)
09-17 16:20:02.055: I/ActivityManager(272): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.sonyericsson.home/.HomeActivity} from pid 272
09-17 16:20:02.126: D/OpenGLRenderer(2115): Flushing caches (mode 0)
09-17 16:20:02.166: D/OpenGLRenderer(2115): Flushing caches (mode 1)
09-17 16:20:07.546: D/dalvikvm(482): GC_FOR_ALLOC freed 1007K, 17% free 9990K/11911K, paused 27ms
09-17 16:20:13.386: D/lights(272): set_light_buttons: brightness=0
09-17 16:20:15.346: D/dalvikvm(1282): GC_CONCURRENT freed 354K, 8% free 6813K/7367K, paused 2ms+2ms
09-17 16:20:16.086: D/dalvikvm(1282): GC_CONCURRENT freed 500K, 9% free 6734K/7367K, paused 2ms+2ms
09-17 16:20:17.456: I/dalvikvm(482): Jit: resizing JitTable from 4096 to 8192
09-17 16:20:18.326: I/ActivityManager(272): START {act=android.appwidget.action.APPWIDGET_UPDATE flg=0x10000000 cmp=com.marcow.birthdaylist/.MainActivity bnds=[2,166][318,234]} from pid -1
09-17 16:20:18.386: I/ActivityManager(272): Start proc com.marcow.birthdaylist for activity com.marcow.birthdaylist/.MainActivity: pid=2137 uid=10122 gids={}
09-17 16:20:18.396: I/dalvikvm(2137): Turning on JNI app bug workarounds for target SDK version 8...
09-17 16:20:18.476: W/Resources(2137): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f060097}
09-17 16:20:18.526: V/PhoneStatusBar(349): setLightsOn(true)
09-17 16:20:18.536: D/TextLayoutCache(2137): Using debug level: 0 - Debug Enabled: 0
09-17 16:20:18.626: I/ActivityManager(272): Displayed com.marcow.birthdaylist/.MainActivity: +247ms
09-17 16:20:18.626: I/dalvikvm(272): Jit: resizing JitTable from 8192 to 16384
09-17 16:20:39.476: D/dalvikvm(272): GC_CONCURRENT freed 1050K, 18% free 11926K/14535K, paused 3ms+7ms

09-17 16:21:08.966: I/ActivityManager(272): START {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.sonyericsson.home/.HomeActivity} from pid 272
09-17 16:21:09.016: D/dalvikvm(2137): GC_EXPLICIT freed 200K, 5% free 6618K/6919K, paused 2ms+2ms
09-17 16:21:09.055: W/InputManagerService(272): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2c1358e0
09-17 16:21:13.156: D/dalvikvm(482): GC_FOR_ALLOC freed 425K, 12% free 10522K/11911K, paused 57ms
09-17 16:21:14.386: D/dalvikvm(1969): GC_CONCURRENT freed 415K, 7% free 7530K/8071K, paused 2ms+13ms
09-17 16:21:17.636: D/dalvikvm(1282): GC_CONCURRENT freed 391K, 8% free 6818K/7367K, paused 2ms+2ms
09-17 16:21:18.126: D/dalvikvm(1282): GC_CONCURRENT freed 526K, 9% free 6738K/7367K, paused 1ms+7ms
09-17 16:21:19.555: I/ActivityManager(272): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.radioopt.widget/com.tm.monitoring.Main bnds=[236,242][310,322]} from pid 482
09-17 16:21:19.626: W/ResourceType(272): Skipping entry 0x7f040033 in package table 0 because it is not complex!
09-17 16:21:19.636: W/ResourceType(272): Skipping entry 0x7f04003d in package table 0 because it is not complex!
09-17 16:21:25.436: D/lights(272): set_light_buttons: brightness=0
09-17 16:21:31.136: D/kernel(135): [  274.770233] bq27520 0-0055: bq27520_handle_soc_worker() capacity=43 (43) flags=0x138 ctrl_status=0x28d soh_state=0x1, valid=1
09-17 16:21:33.526: W/ActivityManager(272): Timeout of broadcast BroadcastRecord{2c1bb9f8 com.android.sonyericsson.android.server.dormant.fastdormancymanager} - receiver=android.app.LoadedApk$ReceiverDispatcher$InnerReceiver@2c1a0bc8, started 10006ms ago
09-17 16:21:33.526: W/ActivityManager(272): Receiver during timeout: BroadcastFilter{2bfb9748 ReceiverList{2bf75e20 272 system/1000 local:2c1a0bc8}}
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.696: I/InputDispatcher(272): Dropped event because it is stale.
09-17 16:21:40.716: I/InputDispatcher(272): Dropped event because it is stale.

09-17 16:22:04.926: I/power(272): *** set_screen_state 0
09-17 16:22:04.936: D/DASH - select(272): sensors_select_callback: select canceled by request
09-17 16:22:04.936: D/DASH - select(272): sensors_select_callback: select canceled by request
09-17 16:22:04.936: D/DASH-bma250_input(272): bma250_input_config_delay: rate:66667000
09-17 16:22:04.956: D/kernel(135): [  308.576141] request_suspend_state: sleep (0->3) at 304938997887 (2012-09-17 14:22:04.934997582 UTC)
09-17 16:22:04.956: D/kernel(135): [  308.576599] as3676 0-0040: as3676_early_suspend
09-17 16:22:04.956: D/kernel(135): [  308.579101] cyttsp-spi spi0.0: cyttsp_suspend: Enter
09-17 16:22:04.966: D/SurfaceFlinger(126): About to give-up screen, flinger = 0xfc48
09-17 16:22:05.126: W/kernel(135): [  308.757202] mddi_sony_ic_off_panel_off [3]
09-17 16:22:05.126: W/kernel(135): [  308.757202] sony_lcd_display_off [3]
09-17 16:22:05.176: W/kernel(135): [  308.812835] sony_lcd_dbc_off [3]
09-17 16:22:05.176: W/kernel(135): [  308.812835] dbc_ctrl = 1
09-17 16:22:05.176: W/kernel(135): [  308.812896] sony_lcd_enter_sleep [3]
09-17 16:22:05.305: W/kernel(135): [  308.938903] sony_lcd_enter_deepstandby [3]
09-17 16:22:10.006: W/ActivityManager(272): Timeout of broadcast BroadcastRecord{2c1aedf0 android.intent.action.TIME_TICK} - receiver=android.app.LoadedApk$ReceiverDispatcher$InnerReceiver@2bf162a0, started 10006ms ago
09-17 16:22:10.006: W/ActivityManager(272): Receiver during timeout: BroadcastFilter{2bf164a8 ReceiverList{2bf16430 272 system/1000 local:2bf162a0}}
09-17 16:22:16.206: D/dalvikvm(455): GC_CONCURRENT freed 868K, 10% free 9231K/10183K, paused 2ms+3ms
09-17 16:22:20.006: W/ActivityManager(272): Timeout of broadcast BroadcastRecord{2c1aedf0 android.intent.action.TIME_TICK} - receiver=android.app.LoadedApk$ReceiverDispatcher$InnerReceiver@2bf19698, started 10000ms ago
09-17 16:22:20.006: W/ActivityManager(272): Receiver during timeout: BroadcastFilter{2bf19910 ReceiverList{2bf19898 272 system/1000 local:2bf19698}}
09-17 16:22:30.026: W/ActivityManager(272): Timeout of broadcast BroadcastRecord{2c0b4468 android.intent.action.SCREEN_OFF} - receiver=android.app.LoadedApk$ReceiverDispatcher$InnerReceiver@2bedd1e0, started 10002ms ago
09-17 16:22:30.026: W/ActivityManager(272): Receiver during timeout: BroadcastFilter{2bedd3c0 ReceiverList{2bedd348 272 system/1000 local:2bedd1e0}}
09-17 16:22:40.036: W/ActivityManager(272): Timeout of broadcast BroadcastRecord{2c0b4468 android.intent.action.SCREEN_OFF} - receiver=android.app.LoadedApk$ReceiverDispatcher$InnerReceiver@2bc19590, started 10003ms ago
09-17 16:22:40.036: W/ActivityManager(272): Receiver during timeout: BroadcastFilter{2bc16668 ReceiverList{2bc17820 272 system/1000 local:2bc19590}}
: E/(): Device disconnected

1 个答案:

答案 0 :(得分:0)

Android的新版本最终通过将窗口标记为KeyGuard来消除了对主键的误用。因此,我相信你在这个问题上运气不好。也许您应该考虑更改您的应用程序设计以遵循标准实现。