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
savi
Posts: 184
Registered: ‎10-28-2009
My Device: Not Specified

Re: switch application select application device become hang?

NO, application is not closed. no error..its is not appearing in switch application.

 

have i written right code at right place?

 

and one more things . if i goto download folder and click on my application then in Menu , my application's menu again added.if click 2 times then its shows three bcoz 1 already added.

 

thanks

Please use plain text.
Administrator
MSohm
Posts: 14,521
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: switch application select application device become hang?

Every time you register an ApplicationMenuItem another item will appear in the menu.  If your application does this on startup it'll add a new item every time it starts up.  You can store a flag in the RuntimeStore that gets set when you add your ApplicationMenuItem.  Your application can then check this flag before it registers the ApplicationMenuItem to determine if the item was already added.  Both the RuntimeStore and ApplicationMenuItemRepository are reset if the user reboots their BlackBerry Smartphone.

 

I'll need to see a larger code sample for your application to figure out the switch application issue.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
savi
Posts: 184
Registered: ‎10-28-2009
My Device: Not Specified

Re: switch application select application device become hang?

 

this is my code

 

 

public class MyAppMain extends UiApplication {

    // private static CannedMain _instance;

    public static void main(String args[]) {
        MyAppMaincm = new MyAppMain();

        /*
         * OptionsManager.registerOptionsProvider(OptionsProviderDemo
         * .getInstance());
         */
        OptionsProviderDemo opd = new OptionsProviderDemo();
        OptionsManager.registerOptionsProvider(opd);
        cm.enterEventDispatcher();

    }

    // Constructor

    public MyAppMain() {

        MessageMenu mm = new MessageMenu(602800, "MyAppMenu");

        ApplicationMenuItemRepository.getInstance().addMenuItem(
                ApplicationMenuItemRepository.MENUITEM_MESSAGE_LIST, mm);
        ApplicationMenuItemRepository.getInstance().addMenuItem(
                ApplicationMenuItemRepository.MENUITEM_SMS_VIEW, mm);
        ApplicationMenuItemRepository.getInstance().addMenuItem(
                ApplicationMenuItemRepository.MENUITEM_SMS_EDIT, mm);

        ApplicationMenuItemRepository.getInstance().addMenuItem(
                ApplicationMenuItemRepository.MENUITEM_PHONE, mm);

        ApplicationMenuItemRepository.getInstance().addMenuItem(
                ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW, mm);

        final FriendsScreen fscreen = new FriendsScreen();
        invokeAndWait(new Runnable() {
            public void run() {
                pushScreen(fscreen);

            }
        });

        // popScreen(getActiveScreen());
    }

}

// Inner class
class MessageMenu extends ApplicationMenuItem {

    /*
     * This class is responsible for add application menu in device's existing
     * applications
     */
    String myname;
    static String phoneNumber;
    static String cellNumber;

    //private ContactList _contactList;
    private Vector _contacts;

    public MessageMenu(int order, String name) {
        super(order);
        myname = name;
    }

    public Object run(Object context) {
        FriendsScreen fs = new FriendsScreen();

        UiApplication.getUiApplication().pushScreen(fs);
        if (context instanceof TextMessage) {
            TextMessage sms = (TextMessage) context;
            phoneNumber = sms.getAddress();
            System.out.println("......................................");
            System.out.println("Phone number :" + phoneNumber);
            System.out.println("value of sms " + sms);
            System.out.println(".........................................");

        }
        if (context instanceof PhoneCallLog) {
            PhoneCallLog phoneCallLog = (PhoneCallLog) context;
            PhoneCallLogID phoneCallLogID = phoneCallLog.getParticipant();
            phoneNumber = phoneCallLogID.getNumber();

            System.out.println("pppppppppppppppppppppppppppppppppp");
            System.out.println("Phone call number: " + phoneNumber);
            System.out.println("pppppppppppppppppppppppppppppppppp");
        }

        if (context instanceof ContactList) {
            
            
            try
            {   
                ContactList _contactList=(ContactList) context;
                _contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
                
                Contact hasEmail = _contactList.createContact();
                hasEmail.addString(Contact.ORG, Contact.ATTR_NONE, "");
                hasEmail.addString(Contact.EMAIL, Contact.ATTR_HOME, "");
                
                Enumeration contactsWithEmail = _contactList.items(hasEmail);
                _contacts = enumToVector(contactsWithEmail);
                phoneNumber=_contactList.toString();   
                
                System.out.println("phone number correspond to email: "+phoneNumber);
                
                       
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

        }

        return context;
    }

    public String toString() {
        return myname;
    }

    public MessageMenu(int order) {

        super(order);
    }
    
    private Vector enumToVector(Enumeration enumeration)
    {
        Vector v = new Vector();

        if (enumeration == null)
            return v;

        while (enumeration.hasMoreElements())
        {
            v.addElement(enumeration.nextElement());
        }
        
        return v;
    }

}

Please use plain text.
Administrator
MSohm
Posts: 14,521
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: switch application select application device become hang?

Note that you don't need to call invokeAndWait from within the constructor of your application because it is being executing on the main event thread already.

 

Can you confirm that this is what you are doing and observing?

 

1.  Open your application and see your FriendsScreen.

2.  Switch to another application (not pressing the escape key).

3.  Switch back to your application and a plain white screen appears.

 

If you replace FriendsScreen with MainScreen, do you see the same behaviour?  What BlackBerry Smartphone model and BlackBerry device software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
savi
Posts: 184
Registered: ‎10-28-2009
My Device: Not Specified

Re: switch application select application device become hang?

i want after switch my application then navigate to friend screen.

 

i am using BB8520 curve and software version 4.6 and platform 4.2

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

Re: switch application select application device become hang?

This code does NOT start your application:

 

FriendsScreen fs = new FriendsScreen();
UiApplication.getUiApplication().pushScreen(fs);

 

This code creates a new FriendsScreen and displays it in the current Application.  In this case, it will be whatever application has run the ApplicationMenuItem.

 

Instead of using this approach, I recommend that you change your ApplicationMenuItem so that it uses a GlobalEvent.  You should start your application at startup, and have it wait for GlobalEvents.  When it receives a GlobalEvent, it should display the FriendsScreen, with the data that you have passed using the Global Event, and bring itself to the foreground.

 

The approach you are currently using, which involves using the initiating application instance, will, I suspect, cause you problems later down the track, especially if you try to write blocking code which could hang the initiating application. 

Please use plain text.