i'm developing an android 1.5-app featuring some remote service and i need to run a thread, that updates some things in my UI with data provided by the remote service every x seconds.
so i did this in my main activity:
Using java Syntax Highlighting
- Handler handler = new Handler();
- Thread thread = new Thread()
- {
- TextView tv;
- @Override
- public void run()
- {
- try
- {
- while(true)
- {
- sleep(8000);
- tv = (TextView) findViewById(R.id.myTextView);
- tv.setText(String.valueOf(myRemoteService.getSomeStringValue()));
- }
- }
- catch (Exception e)
- {
- }
- }
- };
- thread.start();
Parsed in 0.013 seconds, using GeSHi 1.0.8.4
when i run this, the thread does exactly as i intended it to do but when i do something else that needs to update the UI (e.g. in a onClickListener()), it is partly blocked. it "feels" like the whole application sleeps with the thread for the given interval...
additionally, if i do sth like this:
Using java Syntax Highlighting
- public OnClickListener OnClickListener_REFRESH = new OnClickListener()
- {
- @Override
- public void onClick(View view)
- {
- try
- {
- TextView tv = (TextView) findViewById(R.id.funnyTextView);
- tv.setText("" + Integer.valueOf(wlService.getSomeCrazyValue()));
- }
- catch (RemoteException e)
- {
- }
- }
- );
Parsed in 0.013 seconds, using GeSHi 1.0.8.4
the values i try to set via the onclicklistener get cut off at the third character. ("abcdefgh" will be displayed as "abc"...).
how do i get this thread right? it should so some calculation stuff without blocking the UI at all...