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


Vacuum Cleaner Low Noise Dusting Office Desk Vacuum Cleaner Portable Pink picture

Vacuum Cleaner Low Noise Dusting Office Desk Vacuum Cleaner Portable Pink

$14.15



Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool picture

Appion MGAVCT 1/4 Inches MegaFlow Vacuum-Rated Valve Core Removal Tool

$65.08



4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4

4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4"ACME inlet

$29.34



60L Commercial Carpet Cleaner Machine Cleaning Extractor Vacuum Suction Cleaner picture

60L Commercial Carpet Cleaner Machine Cleaning Extractor Vacuum Suction Cleaner

$550.72



DZ-260S Commercial Vacuum Food Packaging Machine Chamber Digital Sealer 120W picture

DZ-260S Commercial Vacuum Food Packaging Machine Chamber Digital Sealer 120W

$302.10



FEBCO 765DBV 3/4in Bronze FNPT Pressure Vacuum Breaker NEW picture

FEBCO 765DBV 3/4in Bronze FNPT Pressure Vacuum Breaker NEW

$89.99







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