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 9006731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:29:27+00:00 2026-06-16T01:29:27+00:00

I am working on a VCard application. here I have started Default Contacts activity(Address

  • 0

I am working on a VCard application. here I have started Default Contacts activity(Address Book).

Now, the flow of application is like this,

  • User Launches the application.
  • Default contact book is opened.
  • User selects a contact from the list and then a Vcard of the selected contact is created.

Now, when the user presses Back Button without selecting any contact, the app gets force closed.

I have overidden BackKeyPress() event, but its not working. The app is still getting force closed.

I am posting the code for reference,

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(intent, 1);
        Log.d("In Oncreate", "Activity Result");
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_BACK) {
         //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
             Toast.makeText(getApplicationContext(), "Back Pressed", 5000).show();
             finish();
         return true;
         }
         return super.onKeyDown(keyCode, event);    
    }
    @Override
    public void onActivityResult(int reqCode, int resultCode, Intent data) {
      super.onActivityResult(reqCode, resultCode, data);

      switch (reqCode) {
        case (1) :
            counter = "Yes";
    Log.d("My Tag", data.getExtras().keySet().toString());
    name_selected = data.getExtras().getString("android.intent.extra.shortcut.NAME");
    Log.d("My Tag", name_selected));
    Intent i = new Intent(getApplicationContext(), BusinessCardActivity.class);
    i.putExtra("name", name_selected);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getApplicationContext().startActivity(i);
       }
    }
}

Logcat Errors:-

12-17 18:41:09.399: E/AndroidRuntime(23456): FATAL EXCEPTION: main
12-17 18:41:09.399: E/AndroidRuntime(23456): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.android.business/com.android.business.ReadContacts}: java.lang.NullPointerException
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.ActivityThread.access$2000(ActivityThread.java:117)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.os.Looper.loop(Looper.java:123)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.ActivityThread.main(ActivityThread.java:3729)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at java.lang.reflect.Method.invokeNative(Native Method)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at java.lang.reflect.Method.invoke(Method.java:507)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at dalvik.system.NativeStart.main(Native Method)
12-17 18:41:09.399: E/AndroidRuntime(23456): Caused by: java.lang.NullPointerException
12-17 18:41:09.399: E/AndroidRuntime(23456):    at com.android.business.ReadContacts.onActivityResult(ReadContacts.java:133)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
12-17 18:41:09.399: E/AndroidRuntime(23456):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)

Here the user is supposed to select a contact from the list, but if the user presses back button without selecting any contact, the app gets force closed.

  • 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-16T01:29:28+00:00Added an answer on June 16, 2026 at 1:29 am

    In your OnActivityResult() do this..

     @Override
      public void onActivityResult(int reqCode, int resultCode, Intent data) {
      super.onActivityResult(reqCode, resultCode, data);
    
      switch (reqCode) {
        case (1) :
         if (data != null && resultCode == RESULT_OK) {
            counter = "Yes";
        // Do some operations on the selected contact
         }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with cakePHP this is my situation: I have Users and Order s. Order
Working through more book examples- this one is a partial poker program- This segment
Working with one of our partners, we have developed now two separate sets of
Working on an application where we would like the user to be able to
Working on an existing webapp (PHP/MySQL) I came to this point: I have 2
Working on a project, I have this issue where my array slicetable returns undefined
Here's what I have tried. Hopefully somebody has a moment to look at this
I am working on an NFC application that works perfectly with some VCard tags.
Working with H2 I get this error when I try to write a row

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.