0

My Query is How to access Fields on the stacked screen using Screen Object ?

The exact problem is as follows:

I have one screen which has one text field (ClientName) when user clicks on that field , application will then push a new screen and it will allow the user to search in remote database using MyWebSerivces. and when user selects the one client from the search result ,i want to set the text Field on the previous screen with the text that user has selected on the current screen..

i have tried the pushScreen( new screen("text) ) and that might be the result if i want to do this operation only once but this is not the option for me since there is two more such field which will go to other screen to fetch the data from webservices . and if i every time i push new screen then after every pushscreen operation i will only get one field set with the desired text

Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
MrPandav
  • 1,831
  • 1
  • 20
  • 24

3 Answers3

1

This not a blackberry (or any specific programming language) related question. This is a question of application architecture and common sense. If one screen should change a Field of another screen, then just pass a reference of the Field to the screen that will change it.

Vit Khudenko
  • 28,288
  • 10
  • 63
  • 91
  • thnx for the rply and yeah it might not be a blackberry question but i was developing a blackberry app and i thought on bb community i wll find the answer. but the way u are suggesting to "pass a reference" in this case i have to push screen and i dont want new screen to be pushed...anyways i found the answer to my question in my question only..chiill – MrPandav Apr 28 '11 at 05:27
0

hi i once had same problem and i did like this:

Screen1

                  ------------------
  Client Name     |  text field     |
                  ------------------

When user clicks on this text field or any button you push Screen2 In screen 2 when user selects a particular value then u do this.

1) take a static variable in main class say clientName. 2) set value of this variable. 3) pop active screen

UiApplication.getUiApplication().getActiveScreen();

when this code is called then u come back to Screen1 Now in screen1 a method is called

    public void  onExposed()
    {
      //here u can set the text in textfield using the static variable 
      invalidate(); // for repainting
    }
Swati
  • 2,870
  • 7
  • 45
  • 87
  • its a good idead to use static variable and set it on onExpsoed event but static value here is not the best option for me when we talk about efficient memory usage and my app is mobile app. and ya, i have found the answer to my question in my question itself. – MrPandav Apr 28 '11 at 05:20
  • oh dats gr8 u got ans, ya static variables should be used when they are required to avoid memory issues. you must post ur answer so that all others can get help too – Swati Apr 28 '11 at 05:32
0

i have found the answer to my question. the solution was there lying in my question but at first i was not able to find it. solution was very simple when i wrote i want to use

UiApplication.getUiApplication().getActiveScreen() 

that was almost the right way and i was proceeding in right direction but the thing that i was missing was " I was not casting the screen (that i have just retrieved form the stack top ) to its type only thing i should have done is "should have casted screen to its type.like this

UiApplication.getUiApplication().posScreen(this)
(MyScreen1) UiApplication.getUiApplication().getActiveScreen() 

now i am able to access all the fields on the retrieved screen (MyScreen1)

things to keep in mind

  1. make sure u cast the screen to its type only otherwise bb will give u resource not found error

Benifits of using screen on Stack

  1. u can use already created screen from the stack no need to create new one
  2. if u will create new screen it will be stacked in memory and will consume more and more memory even if its of no use ( make habit to pop the screen if it is of no use instead of leaving it on stack))
  3. no need to create any static variable since u will be able to set all the field right away from other screen
MrPandav
  • 1,831
  • 1
  • 20
  • 24