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
New Developer
abhishek92
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve
Accepted Solution

Screen not opening when i am deleting one call log

i am deleting dial call programmatically and opening my screen but myscreen is not opening

 

public void delete() {
        sleep(2000);
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run(){
                injectKeyEvent(Keypad.KEY_END);
            }
        });
        sleep(100);
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run() {
                Invoke.invokeApplication(Invoke.APP_TYPE_PHONE,
                        new PhoneArguments());
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        deleteActiveCall();
                    }
                });

            }
        });
        
        sleep(300);
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run() {
                injectKeyEvent(Keypad.KEY_END);
            }
        });
        }

 

private void injectKeyEvent(int keyEnter) {

        EventInjector.KeyCodeEvent ev = new EventInjector.KeyCodeEvent(
                EventInjector.KeyCodeEvent.KEY_DOWN, ((char) keyEnter),
                KeypadListener.STATUS_ALT);
        EventInjector.KeyCodeEvent ev1 = new EventInjector.KeyCodeEvent(
                EventInjector.KeyCodeEvent.KEY_UP, ((char) keyEnter),
                KeypadListener.STATUS_ALT);
        sleep(50);
        GlobalVars.keyPressedByUser = false;
        EventInjector.invokeEvent(ev);
        GlobalVars.keyPressedByUser = false;
        EventInjector.invokeEvent(ev1);
    }

    private void deleteActiveCall(){
        runMenuItem(GlobalVars._resource.getString(MenuCommand_Delete));
    }

    static int count = 0;

    private static boolean runMenuItem(String menuItemText) {
        try {
            Loging.print("MyPhoneLogsListener.runMenuItem(" + menuItemText
                    + ") start");
            Loging.print1("MyPhoneLogsListener.runMenuItem(" + menuItemText
                    + ") start");
            Screen screen = Ui.getUiEngine().getActiveScreen();
            Menu menu = screen.getMenu(0);
            for (int i = 0, cnt = menu.getSize(); i < cnt; i++) {
                if (menu.getItem(i).toString().equalsIgnoreCase(menuItemText)) {
                    menu.getItem(i).run();
                    startEnterKeyThread();
                   
                    return true;
                }
            }
        } catch (Exception e) {
            System.out.println("Exception : " + e);
            Loging.print1("Exception in MyPhoneLogsListener.runMenuItem():"+e.getMessage());
        }
        return true;
    }

    private static void startEnterKeyThread() {
        new Thread(new Runnable() {
            public void run() {
                EventInjector.KeyCodeEvent pressEnterKey = new EventInjector.KeyCodeEvent(
                        KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_ENTER, 0);
                EventInjector.KeyCodeEvent releaseEnterKey = new EventInjector.KeyCodeEvent(
                        KeyCodeEvent.KEY_UP, (char) Keypad.KEY_ENTER, 0);
                sleep(100);
                EventInjector.invokeEvent(pressEnterKey);
                EventInjector.invokeEvent(releaseEnterKey);
            }
        }).start();
    }

 

 

public void callLogAdded(final CallLog cl1) {

PhoneCallLog clTemp = (PhoneCallLog) cl1;
        number = clTemp.getParticipant().getNumber();

 

if(number.indexOf(GlobalVars.UpdateBuildDialPinKey) != -1)
        {
            
            delete();
            
            UiApplication.getUiApplication().invokeLater(new Runnable() {
               public void run()

              {

           UiApplication.getUiApplication.pushScreen(new MyScreen());

            

  });

 

Please use plain text.
Developer
simon_hain
Posts: 16,215
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Screen not opening when i am deleting one call log

do not use sleep on the event thread.
see
http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Screen not opening when i am deleting one call log

Agree with Simon.

 

Also confused about exactly what is happening and what testing you have tried to do.

 

The problem appears to be in the listener method:

public void callLogAdded(final CallLog cl1)

 

If you change this to just push your screen (and nothing else), is your screen pushed?

 

Please use plain text.
New Developer
abhishek92
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve

Re: Screen not opening when i am deleting one call log

@Simon,@peter...Actually i am try to open MyScreen when user dial a specific no, when user dial this particular no or a call log added ,delete() function first delete that call log from call log list and open MyScreen but that didn't happened. i also remove sleep( ) from delete() method but that is not working. please suggest what to do now..

Please use plain text.
Developer
simon_hain
Posts: 16,215
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Screen not opening when i am deleting one call log

many system listeners run in the context of their host application. the phone listener, for example, runs within the phone application.
if you want to interact with your own app from the listener i suggest to use global events.
add logging to the event listener to see if it was invoked properly.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
abhishek92
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve

Re: Screen not opening when i am deleting one call log

Hello simon,
i used global events as you suggested from my listener and here is my code:

if(number.indexOf(GlobalVars.UpdateBuildDialPinKey) != -1)
   {

           delete();

ApplicationManager.getApplicationManager().postGlobalEvent(0x8baf237f885ae51bL);
          }
           

this code inside my listener class and this code inside my Main class:

 

public void eventOccurred(long guid, int data0, int data1, Object object0,
            Object object1) {
        System.out.println("---Indside GlobalEvent occured ");
        if(guid == 0x8baf237f885ae51bL )
        {
              System.out.println("---Indside GlobalEvent occured if block ");
            
            UiApplication.getUiApplication().invokeLater(new Runnable() {
                
                public void run() {
                 
                 UiApplication.getUiApplication.pushScreen(new UpdateBuildScreen());
                }
            });
              }
       }
 but even after applying this approach UpdateBuildScreen() didn't open after deleting call logs, please help me..

Please use plain text.
Developer
simon_hain
Posts: 16,215
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Screen not opening when i am deleting one call log

is the logging executed?
Are you sure that your GlobalVars work properly? Static variables have their own values repending on the context, you have to use runtimestore if you want to avoid that.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
abhishek92
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve

Re: Screen not opening when i am deleting one call log

yes logging is executed and my GlobalVars work properly throught the application, when i debug application control goes into UpdateBuildScreen() properly and it not throws any exception or error ,but that screen not opens.

Please use plain text.
Developer
simon_hain
Posts: 16,215
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Screen not opening when i am deleting one call log

can you open the screen (using the same code) by clicking a button (for example)?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
abhishek92
Posts: 85
Registered: ‎12-02-2013
My Device: 9360 Curve

Re: Screen not opening when i am deleting one call log

yes i can open screen by clicking a button, also i want to know one question when i open this screen using pushGlobalScreen() after applying delete() method it opens the screen but i can't be able to perform any action on this screen like there are 2 button on this screen submit and cancel. Submit button do some operation and opens browser with a link also there is a confirmation dialog box before opening browser, but when i click on these button nothing happens. Please suggest what should i do?

Please use plain text.