0

I have a service which does VCardparsing . I want to execute a method when this is complete . Since my method contains DB query i cant include it directly in the service.

I found that i can check if a service is running from here. But this doesnot serve my purpose. How can I proceed .

EDIT

private void createFavorites() {


        DBAdapter db = new DBAdapter(this);
        db.open();
        Cursor favoriteCursor = db.getAllNumbers();


        Uri contactUri = ContactsContract.Data.CONTENT_URI;
        String[] contactProjection = new String[] {
                ContactsContract.Data._ID,
                ContactsContract.Data.DATA1,// gets number
                ContactsContract.Data.DATA2,// gets type
        };

        Cursor contactCursor = managedQuery(contactUri, contactProjection,
                null, null, null);

        CursorJoiner joiner = new CursorJoiner(favoriteCursor,
                new String[] { DBAdapter.KEY_NUMBER }, contactCursor,
                new String[] { ContactsContract.Data.DATA1 });

        MatrixCursor cursor = new MatrixCursor(new String[] { "number"}, 10);
        for (CursorJoiner.Result joinerResult : joiner) {
            switch (joinerResult) {
            case BOTH: // handle case where a row with the same key is in
                String id = contactCursor.getString(0);
                // String secret_identity = sipCursor.getString(1);
                cursor.addRow(new String[] { id });
                break;
            }
        }
        db.close();
        Log.d(LOG_TAG, "final favorite contact " + cursor.getCount() + favoriteCursor.getCount() + contactCursor.getCount());

    }

what I am trying to do here is that, I already have a database which holds my favorite numbers . When I parse a vcf if that number is present in one of those vcfs I want to mark them as favorites.

Community
  • 1
  • 1
Rohit Walavalkar
  • 790
  • 9
  • 28

1 Answers1

0

you need to use a IntentService and after complete all operation in service send a Message to your related activity, then execute the method, BTW what do you mean by "Since my method contains DB query i cant include it directly in the service" , you can access DB in Services also

Kapil Vats
  • 5,485
  • 1
  • 27
  • 30
  • I googled and got to know that I cant use the method managedquery() in service class . One more question what if I call the service from a regular class not from an activity ? – Rohit Walavalkar Feb 26 '13 at 07:05
  • you no need to use managedquery() , can you post the code where you are using managedQuery() – Kapil Vats Feb 26 '13 at 07:10
  • I can actually use getcontentresolver() and then use query() instead of managedquery() . Thanks for the help – Rohit Walavalkar Feb 26 '13 at 09:02