• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Android: Cannot show more than one image

 
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have the following main class and thread-TCP Client. The client runs in a loop, receives messages and passes it to main class. In the main class, I parse the message and try to show different images based on the name and value of the message received. Ex: shiftDirection1 name: shiftDirection & value: 1

But I can show only the image corresponding to the first received message and the images corresponding to the remaining received messages cannot be displayed.

Please go through the code below and kindly suggest the mistake/problem and alternative ways.

Thank you for your time and efforts.

Madhu

main class:



Only the image corresponding to the first if case is displayed. The program control enters the second if loop but does not show the image there.

Interface:



Thread (TCP Client):

 
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does actionOnData ever get called a second time?
 
Madhu Nandan
Ranch Hand
Posts: 52
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daniel Trebbien wrote:Does actionOnData ever get called a second time?



Of course... Every time there is a new message read in the client (thread), it is passed to the parser and after parsing, the actionOnData is called from the parser.
 
Daniel Trebbien
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the problem is that the calls to actionOnData are not executing on the UI Thread.

Bear with me...

One thing that you can do to make the programming cleaner is to switch to using a pull parser to parse the messages that are generated by the service running at 192.168.62.23:1200.

Currently you expect data from the service to be:



This is rather brittle. What if your service responded with a true XML document:



You can parse this with a streaming XML parser:



Now, the TcpHandler class is implemented as follows:



And TcpListener is:



Your TcpListen activity becomes:



Then get rid of the callCompleted method.

All of the above is an extremely rough sketch of the idea, and it probably does not compile as I wrote it quickly outside of an IDE. But, it should give you enough details to get started.

Try implementing this approach and posting the result.
 
please buy this thing and then I get a fat cut of the action:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic