简体   繁体   English

检索当前的活动屏幕名称Blackberry

[英]Retrieve current active screen name Blackberry

My application is a tab based one. 我的应用程序是基于标签的应用程序。 For example, app has got 3 tabs - A, B & C. If the currently opened tab is "A", when the user again tries to click on the same tab, app shouldn't do anything. 例如,应用程序有3个选项卡-A,B和C。如果当前打开的选项卡是“ A”,则当用户再次尝试单击相同的选项卡时,应用程序不应执行任何操作。

I tried to do this using the following code snippet 我尝试使用以下代码段执行此操作

final Screen currentActiveScreen = UiApplication.getUiApplication().getActiveScreen();

        if (newScreen == currentActiveScreen)
        {
            return;
        }

New screen is the screen that the user is trying to navigate to. 新屏幕是用户试图导航到的屏幕。

But this code is not firing and when I tried to debug, I found that some random number is also coming with the screen and hence the code is not entering the if loop. 但是这段代码没有触发,并且当我尝试调试时,我发现屏幕上也出现了一些随机数,因此代码没有进入if循环。

The values in the condition comes like this and is returning false. 条件中的值是这样的,并且返回false。 AScreen@497293b7 == AScreen@2f25c01e AScreen @ 497293b7 == AScreen @ 2f25c01e

So, Is there anything wrong in what I'm trying to do ? 所以,我要做什么有什么问题吗? How can we get the screen name only. 我们如何仅获取屏幕名称。

Thanks in advance. 提前致谢。

There's not much to go on here, you may need to add more detail. 这里没有太多事情要做,您可能需要添加更多细节。

Those numbers you're seeing are the hashcodes of the objects. 您看到的那些数字是对象的哈希码。 If newScreen refers to a new instance of a screen, == wont evaluate to true. 如果newScreen引用屏幕的新实例,则==不会计算为true。 There are 2 choices that come to mind, either override the equals method of your custom screen; 有两种选择,一种是覆盖自定义屏幕的equals方法;另一种是覆盖自定义屏幕的equals方法。 or make A,B, and C different classes (they most likely are already), then use instanceof 或将A,B和C设置为不同的类(它们很可能已经存在),然后使用instanceof

eg. 例如。

ScreenA newScreen = new ScreenA();
if (currentActiveScreen instanceof ScreenA) return;

There is no such thing as a screen name in BlackBerry Java. BlackBerry Java中没有屏幕名称之类的东西。 And Kevin is right - you cannot compare the screens directly (for the reasons explained in his reply). 凯文(Kevin)是对的-您无法直接比较屏幕(出于他的答复中所述的原因)。 You need to define your own discerning mechanism to check the type of the screen you would navigate to before even creating it. 您需要定义自己的识别机制,以在创建屏幕之前检查要导航到的屏幕的类型

If you have 3 tabs, you can pre-create 3 screens (one per tab), store them in three members of your Object, then simply remove and add the needed screen when the user presses something. 如果有3个选项卡,则可以预先创建3个屏幕(每个选项卡一个),将它们存储在Object的三个成员中,然后在用户按下某些按钮时简单地删除并添加所需的屏幕。 Before doing that, you can indeed compare the screen you are trying to bring up with the current one. 在此之前,您确实可以将要显示的屏幕与当前屏幕进行比较。

Something like this: 像这样:

Screen tabA = new MyScreenForTabA();
Screen tabB = new MyScreenForTabB();
Screen tabC = new MyScreenForTabC();
//...
// Somewhere else in the code
//...
    Screen nextScreen;
    switch (chosenTabLetter) { // Just throwing an idea
        case 'A':
            nextScreen = tabA;
            break;
        case 'B':
            nextScreen = tabB;
            break;
        case 'C':
            nextScreen = tabC;
            break;
    }
    if (nextScreen == currentScreen) {
        return;
    }

This way you can juggle the three screens without constantly creating new ones. 这样,您可以在不不断创建新屏幕的情况下处理三个屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM