BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 01-22-2007, 09:24 AM   #1
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default "Application Already Running in this Process" error with MenuItem

Please Login to Remove!

I've written a blackberry application that has three different menu items. For one of the menu items I wish an application to be launched with the contact details of the selected contact when the menu was clicked.

Here is my main method:

Code:
public class App
{
    public static void main (String[] args)
    {
        // register all of the menu items
        (new ChangeTelMenuItem()).registerInstance();
        (new BluetoothSyncMenuItem()).registerInstance();
        (new LookupTelMenuItem()).registerInstance();
    }
}
Here is the ChangeTelMenuItem code:

Code:
package com.roke.blackberry;

import javax.microedition.pim.Contact;

import net.rim.blackberry.api.menuitem.ApplicationMenuItem;
import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository;
import net.rim.device.api.ui.component.Dialog;

public class ChangeTelMenuItem extends ApplicationMenuItem
{
    ChangeTelMenuItem ()
    {
        super( 0 );
    }


    public void registerInstance ()
    {
        ApplicationMenuItemRepository a = ApplicationMenuItemRepository.getInstance();
        a.addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST, this );
        a.addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSCARD_EDIT, this );
    }


    public Object run (Object o)
    {
        if (o instanceof Contact)
        {
            // load the application to modify the details!
            ChangeDetails cd = new ChangeDetails((Contact)o); // PROBLEM ON THIS LINE
            cd.enterEventDispatcher();
        }
        else
        {
            Dialog.alert( "NOT contact" );
        }
        return null;
    }


    public String toString ()
    {
        return "Change Tel Details";
    }
}
I've added a comment on the line that causes a runtime exception, with the message application already running in this process. The code for ChangeDetails is:

Code:
public class ChangeDetails extends UiApplication
{
    public ChangeDetails (Contact contact)
    {
        pushScreen( new ChangeDetailsScreen(contact) );
    }


    private class ChangeDetailsScreen extends MainScreen
    {
        ChangeDetailsScreen (Contact contact)
        {
            super();

            // add title
            LabelField title = new LabelField( "Change Tel Details", LabelField.ELLIPSIS
                | LabelField.USE_ALL_WIDTH );
            setTitle(title);

            // display contact details
            add(new RichTextField(contact.toString()));

        }
    }
}
I've seen on another forum post that one way around this is to init the cd class outside of the run method - but then it wouldn't be possible for me to pass it the contact object.

Any ideas on how I could get this working?

Thanks in advance,

Ben
Offline  
Old 01-22-2007, 11:28 AM   #2
bdowling
Thumbs Must Hurt
 
Join Date: Jan 2007
Model: 8800
Carrier: Orange
Posts: 181
Default Fixed

I managed to solve this one! It involved changing the problem line in the ChangeTelMenuItem class to:

Code:
UiApplication.getUiApplication().pushScreen( new ChangeDetails((Contact)o) );
And changing the ChangeDetails class to:

Code:
public class ChangeDetails extends MainScreen
{
    ChangeDetails (Contact contact)
    {
        super();

        // add title
        LabelField title = new LabelField( "Change .Tel Details", LabelField.ELLIPSIS
            | LabelField.USE_ALL_WIDTH );
        setTitle( title );

        // display contact details
        String[] nameArray = contact.getStringArray( Contact.NAME, 0 );
        String name = nameArray[Contact.NAME_GIVEN] + " " + nameArray[Contact.NAME_FAMILY];
        add( new RichTextField( "Change details for " + name ) );

    }
}
Hope that helps someone else!

Cheers, Ben
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


NEW Mitsubishi A1SNMCA-8KE Memory Cassette picture

NEW Mitsubishi A1SNMCA-8KE Memory Cassette

$151.62



WIFI Audio Voice Recorder Live Real-Time Audio Thru App | Charger & 32GB SD Card picture

WIFI Audio Voice Recorder Live Real-Time Audio Thru App | Charger & 32GB SD Card

$129.00



New Sealed AB 2080-MEMBAK-RTC Memory Backup, Data Log, Recipe ,High Accuracy RTC picture

New Sealed AB 2080-MEMBAK-RTC Memory Backup, Data Log, Recipe ,High Accuracy RTC

$281.95



Argolladora We R Memory Keepers Heidi Swapp Cinch Binding Machine 71050-9 by AC picture

Argolladora We R Memory Keepers Heidi Swapp Cinch Binding Machine 71050-9 by AC

$79.99



WiFi Audio Voice Recorder Audio Alerts Check Audio Real-Time 32GB USA Shipper picture

WiFi Audio Voice Recorder Audio Alerts Check Audio Real-Time 32GB USA Shipper

$129.00



NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In picture

NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In

$284.77







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.