thread blocks application!?

Put your problem here if it does not fit any of the other categories.

thread blocks application!?

Postby xenonite » Mon Jun 14, 2010 1:15 pm

hi there!

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Handler handler = new Handler();
  2. Thread thread = new Thread()
  3. {
  4.         TextView tv;
  5.        
  6.         @Override
  7.         public void run()
  8.         {
  9.                 try
  10.                 {
  11.                         while(true)
  12.                         {
  13.                                 sleep(8000);
  14.                                
  15.                                 tv = (TextView) findViewById(R.id.myTextView);
  16.                                 tv.setText(String.valueOf(myRemoteService.getSomeStringValue()));
  17.                         }
  18.                 }
  19.                 catch (Exception e)
  20.                 {
  21.                        
  22.                 }
  23.         }
  24. };
  25. thread.start();
  26.  
Parsed in 0.032 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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public OnClickListener OnClickListener_REFRESH = new OnClickListener()
  2. {
  3.         @Override
  4.         public void onClick(View view)
  5.         {
  6.                 try
  7.                 {
  8.                         TextView tv = (TextView) findViewById(R.id.funnyTextView);
  9.                         tv.setText("" + Integer.valueOf(wlService.getSomeCrazyValue()));
  10.                 }
  11.                 catch (RemoteException e)
  12.                 {
  13.                 }
  14.         }
  15. );
  16.  
Parsed in 0.032 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...
xenonite
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Apr 08, 2010 12:45 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 13 guests