Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:53:52+00:00 2026-06-03T12:53:52+00:00

I am trying to tidy up my code so that I can easily reuse

  • 0

I am trying to tidy up my code so that I can easily reuse elements without having to duplicate work/ code.

I have a contactpicker and code to process the result in my application that I want to put into its own external class so I can reuse it in multiple areas.

I have got stuck on one issue- in order to call the StartActivityforResult, I need to pass the activity to the external class- however I am not sure how to do that?

Here is the class I am using as the external contact picker:

    public class ContactFinder {

    private static final int CONTACT_PICKER_RESULT = 1001;
    private Activity atv;
    public ContactFinder(Activity atv) {
        this.atv=atv;
    }
public void startContactPicker()
{
    Intent contactPickerIntent=new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
    //Shows CONTACT_PICKER_RESULT cannot be resolved to a variable
    atv.startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);

}
}

so how would I call it from my main activity using the following:

ContactFinder cf=new ContactFinder(???));// how do I pass the activity to this external class

cf.startContactPicker();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:53:53+00:00Added an answer on June 3, 2026 at 12:53 pm

    Pass this as Activity in which you are creating this Object.

    ContactFinder cf=new ContactFinder(this);
    cf.startContactPicker();
    

    Keep in mind to implement onActivityResult() in your Activity also, to handle the result given by the started Activity.

    Better to have a basic Activity class to which will implement onActivityResult() for your ContactFinder and extend every Activity (in which you want to use ContactFinder) from basic Actvitiy

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
i am trying to tidy up my code, i have a number of projects
I am trying to tidy up my code now that Delphi XE2 is available
I'm trying to tidy up my code. I have an array with 5 columns,
I'm trying to tidy all my css code on my site, I want to
Trying to tidy up scope and avoid possible multiple calls to RegisterWindowMessage. Currently have
I have a class that generates some html (form elements and table elements), but
I am trying to keep my code tidy and move most of the functionality
I am trying to tidy up an application, and have manually been doing Constructor
We are in the process of trying to tidy up our users home directories

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.