Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

I presume you have added the field to a normal MainScreen to prove to yourself that it does work?

 

I'm concerned about the following statement:

"I ve put all those network work in to a different thread using invokelater()"

 

This does not put the network activity on a different Thread.  It just puts it on the Event Thread to be run later.  To start background activity like the network processing you should create a Thread as normal and then use

<Thread>.start();

 

Can you change your code to correctly invoke the Network Thread as a background Thread and see what happens.

Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

Ya sure.. Will try and let you know.. 

 

Thanks a lot.

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

@peter

I created a new thread and used Thread.run(arg1,arg2) with some arguments as shown. Now the loading screen does'nt show at all.. What do you think i am doing wrong. 

 

 

The code is like so.In the actual function 

 

I am using loadscreen.show () which contains the animation .

 

Then in the thread call i use   thread.run(loadscreen).

 

In the run() method after the connection completes , i am calling loadscreen.close() 

 

 

I tried to put a sleep() in the threads run method to see if its jus executing really fast , but it doesnt.

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

I've lost the plot on this problem sorry.

 

However, and please don't take this the wrong way, but rather than attempt to go though it all again, I am really concerned that you do not understand Threading and the way Threads should be used.  There are these important things that I think have come up in this discussion:

 

1) <Thread>.run, does not start a new Thread, it executes the run method on the current Thread.

 

2) invokeLater, invokeAndWait also do not start a new Thread.  The Runnable contained is executed on by the Event Thread.

 

3) To do networking you need to have your network Thread running off the Event Thread.  so you need to a

<Thread>.start();

 

4) Code within the networking Thread should not directly update the user Interface.

 

Now looking at what you are trying to do.

 

The Animated GIF is basically a normal BitmapField, which has a special paint routine that selects one of the gifs in the Animation to display.  The 'bump' that causes this process to work comes from a separate Thread, however the update to the picture must run on the Event Thread.  The 'bump' is an invalidate(), this will indirectly result in the paint method of the Animated gif Field being invoked.  Do you understand this processing?

 

And to complicate this, remember that your network Thread needs to initiate the display of the Animated GIF and also dismiss it when it has completed.

 

So what you are trying to do is not simple. 

 

But if I see you coding things like

<Thread>.run()

then this suggests to me that you don't understand how Threading actually works.  If you don't understand that, you are never going to get this to work properly, and it will fall apart in a way that will really confuse you. 

 

So at this stage I would recommend that you discard the Animated Gif, and try to implement your network Thread, properly.  And no, sample code is not the the right answer, I think you need to understand the code, not copy it.  So I recommend that you go back to the httpdemo code supplied, crawl all over it attempting to understand how it uses the Event Thread, then change it so that it displays a screen that it then dismisses. 

 

Since Java Threading is not BB specific, you will find resources on the Web that should explain how this works.  Review the Event Thread video

 

Sorry not being mean here, just trying to make sure that you are developing something you can maintain.

Please use plain text.
Developer
mlisaoverdrive
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

Hey Peter,

I did get the application working with the structure you recommended.  I thought it was running well enough to deploy to my device and start using, which I did...but now I've run into a new problem.  Do you want me to post it in this thread, or start a new one?

 

 

Please use plain text.
Developer
mlisaoverdrive
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

 


nirmalsat wrote:

Peter :

 

 

I have a problem with the gif field. What i am trying to do is show a progress screen when there is some network activity. I ve put all those network work in to a different thread using invokelater() and in the main event thread i am displaying the gif image. Inside the runnable after the network work is done am closing the image. All this works fine. The image comes up during the network operation and when its done it closes. The problem is , its no longer an animation. Its as though it just renders the first frame of the gif image . I initially thought it was cos the network activity was pretty fast but it was the same even after i put a Thread.Sleep() in the runnable. 

 

I have already checked if the image was converted by the compiler. It has not .

 

Any help would be great.. 

 


 

You probably want to post this in a different thread to avoid confusion.  If you do, can you post the code so we can see what you're doing?

 

Please use plain text.
Developer
mlisaoverdrive
Posts: 179
Registered: ‎09-11-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

Ignore the above.  I didn't see the third page of this thread when I posted it.

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

I think we should close this Thread off, it is quite long enough!

 

So new Thread for everyone is my vote!

Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

[ Edited ]

Thanks peter and your not being mean. I understand that i need to learn it properly cos in the end its only gonna help me out in the long run. Thank you for taking the time to reply. I shall learn properly and get back.. 

 

And if its not stepping over the line i just have one small question..

 

U said " Thread.run () " does not start a new thread. 

 

Is this true even if u have a new class that extends thread and then i create an object of this class and what if i call the thread.run then. I am having this doubt cos i read in some article that u can start a thread either by calling the start or the run. 

To better put it heres sample code : Please excuse the use of the noobest of code(Couldnt really think of a simpler way to explain..Sorry)

 

 

Class screen
{
public void screen()
{
   Animatedscreen popscreen = new Animatedscreen();
   popscreen.show();
   Networkthread thread = new Networkthread ();
   thread.run(popscreen);
}
}

Class Networkthread extends Thread 
{
public void run(Animatedscreen popscreen)
{
   // Network task here
     popscreen.close();
}
}

All i want to know is , does this start a new thread or not.. Just a Yes or a No would do.. Sorry if i am testing ur patience.

 

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: AnimatedGIF popup: Appears When PushScreen Only, But Not When PushScreen, then PopScreen When Do

"its not stepping over the line"  Of course not.  I want everyone to learn!

 

"i read in some article that u can start a thread either by calling the start or the run." - Please point me at that article.  As far as I am aware, this comment is not correct.

 

"does this start a new thread or not" - The run method you have shown does not start a new Thread.

Please use plain text.