×

Discussion Board

Results 1 to 5 of 5

Thread: contacts

  1. #1
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322

    contacts

    Hi
    I develop an application that shows all of the contacts names in a list ,
    when starting the application I load all of the names into an array , as you can see below.
    2 questions :
    1) how can I make the "load" faster ??? any ideas ? any corrections to what I wrote ?
    2) when going back to the app menu and then returning to the app - there is no load time because the array still exists in the memory.
    but when exiting the application and opening it again - the contacts have to reload - do you have any idea how can I solve this ? (I know that the regular contacts application loads only one time - the first time it is executed after turning the mobile on).

    Thanks a lot in advance , TE
    Code:
    //calling InitContacts when starting the application 
    if(iAppUi->iController->loadContacts) 
       { 
          iAppUi->iController->arrayContacts = NULL; 
          iAppUi->iController->arrayContacts = new CDesCArrayFlat(1); 
          iAppUi->iController->InitContacts(iAppUi->iController->arrayContacts ); 
          iAppUi->iController->loadContacts = EFalse; 
       } 
    
    // the InitContacts method 
    void CMyAppController::InitContacts(CDesCArrayFlat* contactsArray) 
    { 
       TFileName contactDbFilePath; 
       CContactDatabase::FindContactFile(contactDbFilePath); 
       CContactDatabase * contactsDb = CContactDatabase::OpenL(contactDbFilePath); 
       CleanupStack::PushL(contactsDb); 
       contactsDb->SetDbViewContactType(KUidContactCard); 
       // set the contact db view to look only at contacts (not groups) 
       contactsDb->SetDbViewContactType(KUidContactCard); 
       // sort the contacts by last name and first name 
       CArrayFixFlat<CContactDatabase::TSortPref>* aSortOrder = 
             new CArrayFixFlat<CContactDatabase::TSortPref>(2); 
       aSortOrder->SetReserveL(2); 
       TFieldType fieldType = KUidContactFieldFamilyName; 
       CContactDatabase::TSortPref::TOrder order = 
             CContactDatabase::TSortPref::EAsc; 
       CContactDatabase::TSortPref sortPref1(fieldType, order); 
       aSortOrder->AppendL(sortPref1); 
       fieldType = KUidContactFieldGivenName; 
       CContactDatabase::TSortPref sortPref2(fieldType, order); 
       aSortOrder->AppendL(sortPref2); 
       contactsDb->SortByTypeL(aSortOrder); 
       // now loop through and extract the contact names 
       const CContactIdArray* iContactIdArray; 
       iContactIdArray = contactsDb->SortedItemsL(); 
       CContactItem* card; 
       arrayCardId = new TContactItemId[iContactIdArray->Count()]; 
       if (iContactIdArray->Count() > 0) 
       { 
          for (TInt i = 0; i < iContactIdArray->Count(); i++) 
          { 
             TContactItemId nextContactId = (*iContactIdArray)[i]; 
             card = contactsDb->OpenContactL(nextContactId); 
             CleanupStack::PushL(card); 
             TInt firstNameField = card->CardFields().Find(KUidContactFieldGivenName); 
             if(firstNameField!=KErrNotFound) 
             { 
                TBuf<32> nameBuf; 
                if(firstNameField!=KErrNotFound) 
                   combined.Append(card->CardFields()[firstNameField].TextStorage()->Text()); 
                contactsArray->AppendL(nameBuf); 
                arrayCardId[i]=nextContactId; 
             } 
             contactsDb->CloseContactL(nextContactId); 
             CleanupStack::PopAndDestroy(card); // card 
          } 
       } 
       CleanupStack::PopAndDestroy(); // contactsDb 
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    17
    Hi,
    You can check this example application

    http://www.forum.nokia.com/main/1,65...ml&fileID=4857

    BR,
    DC

  3. #3
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322

    Thanks

    I checked this example on my device - it took twice the time to load the contacts :-(

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015
    Try increasing your array granularity to something bigger than 1, probably won't make a lot of difference but creating arrays with that granulatiry is wrong. Make it 50 or something.

    The contacts engine probably only loads its contacts once because the contacts app is probably always running on your particular device and so it never quits.

    If you quit your application all your memory sturctures will disappear, the only way to prevent a slow load up time is to save your array to a file and read in in next time, but if the contacts have changed while your app hasn't been present then you will have old data which is no use.
    So there's not much you can do about it unfortunalty (you could write your engine as a server that permanently runs but thats very very much overkill and hogs memory).

  5. #5
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    322

    thanks

    :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •