problem with handler

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

problem with handler

Postby swordi » Wed May 27, 2009 1:11 pm

hey

i have an activity called startactivity. from this i start a second activity by button

in the second one i create a handler which interacts like a new thread for 26 seconds. ( it checks every 600 ns something )

the problem is when the user clicks the back button on the phone. i tried

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. handle.removeCallbacks(gr);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


in the onPause() but without success. the handle runs further and brings an exception after 26 seconds because of an alert on the wrong activity called from the handler callback method.

how can i cancel the handler correctly?

thx
swordi
Developer
Developer
 
Posts: 46
Joined: Tue May 19, 2009 9:44 am

Top

Postby sujay » Wed May 27, 2009 1:19 pm

use onkeydown & check for keycode == KeyEvent.KEYCODE_BACK...
'm not very sure if this is wat u need... but jus give it a try...
sujay
Junior Developer
Junior Developer
 
Posts: 14
Joined: Wed May 20, 2009 11:01 am

Postby swordi » Wed May 27, 2009 1:28 pm

thx man

i was looking for onkey down with back too ;) but it dont resolve my problem

debug error message looks like this
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Uncaught handler: thread main exiting due to uncaught exception
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


handler is like this
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void run() {
  2.  
  3.       if (Game.getInstance().getActTime() >= Game.getInstance().getMaxTime()) {
  4.  
  5.         if (finish == false) {
  6.  
  7.                 System.out.println("GameOver");
  8.  
  9.                 alert.show();
  10.  
  11.         }
  12.  
  13.                
  14.  
  15.       }
  16.  
  17.       else
  18.  
  19.         handle.postDelayed(this, 200);
  20.  
  21.         }
  22.  
  23.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


hope you have another hint for me ;)
swordi
Developer
Developer
 
Posts: 46
Joined: Tue May 19, 2009 9:44 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests