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
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem in pushing screen from background to foreground

The code is already in Thread.

 

It is already in the form you have given.

 

I have pasted it below

 

public void run()
{
   
    while(true)
    {
        try
        {
            if(isScreenPushedToForeGround && !ApplicationManager.getApplicationManager().inStartup())
            {

                try
                {
                   
                    sop("isScreenPushedToForeGround....");
                    UiApplication.getUiApplication().invokeLater(new Runnable()
                    {

                        public void run()
                        {
                           
                           
                            requestForeground();
                            sop("isScreenPushedToForeGround333");
                                                   
                           
                            try
                            {
                             
                              UiApplication.getUiApplication().pushScreen(new PreRegistrationList());
                            }
                            catch(Throwable t)
                            {
                               sop("1111111111111111111111111111111");
                               t.printStackTrace();

                            }
                            sop("isScreenPushedToForeGround444");
                                               
                            isScreenPushedToForeGround = false;

                        }
                    });
                }
            }
        }

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Problem in pushing screen from background to foreground

I see somewhere peter_strange suggesting to put like I posted (Thread, rather than invokeLater) .. OK, check if it is an event thread by this code in your try:

 

sop(""+Application.getApplication.isEventThread());

 

Cheers... 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem in pushing screen from background to foreground

It is returning true..
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Problem in pushing screen from background to foreground

As expected, so your operation is on event thread.. I would encourage you to review this video..

http://www.blackberry.com/DevMediaLibrary/view.do?name=WhatistheEventThread 

 

OK now try mine, encapsulate the code in a thread and and do t.start() as I said in two more posts earlier..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem in pushing screen from background to foreground

public void run()

{

  while(true)
        {
            try
            {
                sop("the thread is:"+Application.getApplication().isEventThread());
                if(isScreenPushedToForeGround && !ApplicationManager.getApplicationManager().inStartup())
                {

                    try
                    {
                       
                        sop("isScreenPushedToForeGround....");
                        UiApplication.getUiApplication().invokeLater(new Runnable()
                        {

                            public void run()
                            {
                                sop("isScreenPushedToForeGround111");
                                unHideApplicationIcon();
                                sop("isScreenPushedToForeGround222");
                                requestForeground();
                                sop("isScreenPushedToForeGround333");
                                //                                 System.out.println("Requesting forground.......");
                                //                                pushScreen(new MainList());
                               
                                try
                                {
                                  sop("the thread is:"+UiApplication.getUiApplication().isEventThread());
                                  pushScreen(new PreRegistrationList());
                                }
                                catch(Throwable t)
                                {
                                   sop("1111111111111111111111111111111");
                                   t.printStackTrace();

                                }

 

 

I have marked both the sop in bold....

 

The 1st sop returns false and the 2nd one returns true....

 

Where you had asked me to place  UiApplication.getUiApplication().isEventThread()

 

My parent Thread is not an EventThread... the invokeLater Thread returns true....

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Problem in pushing screen from background to foreground

Why should not you give a try on what I suggested? Encapsulating pushScreen in a new thread? 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem in pushing screen from background to foreground

[ Edited ]

I tried the code provided by you.....

 

Encapsulating it in  a seperate thread, it is not throwing any error or Exception  but the device is not pushing the screen to the forground.

 

The code looks something like this...

 

public void run()
    {
        while(true)
        {
            try
            {
                sop("the thread is:"+Application.getApplication().isEventThread());
                if(isScreenPushedToForeGround && !ApplicationManager.getApplicationManager().inStartup())
                {
                     callThread();

                     isScreenPushedToForeGround = false;

 

                 }

 .........

 

 public void callThread()
    {
       
        try{
            sop("callThread>>"+1);
            Thread t1 = new Thread()
            {

                public void run()
                {
                    sop("callThread>>"+2);
                    requestForeground();
                    pushScreen(new PreRegistrationList());

                }

            };
            sop("callThread>>"+3);
            t1.start();

            }

            catch(Throwable t)
            {
                sop("callThread excep>>"+1);
               t.printStackTrace();

            }
    }

 

 

I was force to use invokeLater Thread  because the device pushes the screen on the foreground using this Thread only.

 

Thr problem is only with 4.2.1. the above versions are working perfctly as desired using the invokeLater Thread...

 

 

 

Thanks...

Message Edited by safycool on 07-23-2009 09:25 AM
Message Edited by safycool on 07-23-2009 09:31 AM
Message Edited by safycool on 07-23-2009 09:35 AM
Message Edited by safycool on 07-23-2009 09:47 AM
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem in pushing screen from background to foreground

I switched the entire Project from Blackberry Eclipse Plugin 4.2.1 to Blackberry JDE 4.2.0.

 

The blackberry JDE 4.2.0 gave me proper Exception which helped me to resolve the Error.

 

Basically I was loading bmp images in Preregistration List. JDE 4.2.0 does not support bmp. I replaced all the images

 

from bmp to png, and atlast Its working perfectly. Mantaker thanks for the support.

 

 

Thanks....

Highlighted
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Problem in pushing screen from background to foreground

Why 4.2.1 doesn't give a detailed error.. But still I would suggest catching Throwable instead of Error or Exception in the future for a more detailed debug report..

 

Good that you got it solved, resolve this thread.. Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem in pushing screen from background to foreground

I dont know why Eclipse plugin 4.2.1 was not indicating the point of Error. It was just going to the hang Mode with a java.lang.Error. When I migrated the project to Balckberry JDE 4.2.0( not the Eclipse plugin) It pointed the image object with a Null pointer Exception.