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

The Archive Base Latest Questions

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

I am having trouble using onActivityResult and cannot figure out why the below code

  • 0

I am having trouble using onActivityResult and cannot figure out why the below code is crashing.

I have a button in my main activity that starts another activity for result.

    //---Setting the button for choosing a message---
    btn3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            // startActivity(new Intent("kurt.steveboss.textChooserView")); 
            startActivityForResult(new Intent(
                    "kurt.steveboss.textChooserView"),
                    request_CodeText);
        }

    });

This brings up a new view. In this view when a user clicks a button some text inside an EditText is captured and returned to the mainActivity as the result.

        //---Setting the button for generating a random message---
    btn6.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {

            Intent data = new Intent();

            //Extract the message from the EditText 
            data.setData(Uri.parse(txtMessage.getText().toString()));
            setResult(RESULT_OK, data);

            //---closes the activity---
            finish();               
        }
    });  

I then have an onReceive in my mainActivity (there is more than one intent here, this one of course is listenting for the case of “request_CodeText”

    public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    switch(requestCode) {
    case request_CodeText:
        Uri uri = data.getData();
        final Button btn3 = (Button)findViewById(R.id.btnMessage);
            if(resultCode == RESULT_OK) {
            btn3.setText((String) uri.toString());
            }
            else if(resultCode == RESULT_CANCELED) {
                //no action
            }
        break;

    case request_CodeNumber:
        Uri uri2 = data.getData();
        Cursor c = null;
        try {
            c = getContentResolver().query(uri2, new String[]{
                    ContactsContract.CommonDataKinds.Phone.NUMBER,
                    ContactsContract.CommonDataKinds.Phone.TYPE,
                    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
                    null, null, null);
            if (c!= null && c.moveToFirst()) {
                String number = c.getString(0);
                int type = c.getInt(1);
                String contactName = c.getString(2);
                showSelectedNumber(type, number, contactName);
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
    break;
    }
}

This onActivityResult works to the extent that the button 3 text is updated (so it is working up to that point). But then the app crashes with the following in the LogCat

12-21 15:10:15.995: I/ActivityManager(2098): START {intent.toShortString} from pid 19907
12-21 15:10:16.000: I/power(2098): *** acquire_dvfs_lock : lockType : 1  freq : 1000000 
12-21 15:10:16.000: D/PowerManagerService(2098): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 1000000  uid : 1000  pid : 2098  tag : ActivityManager
12-21 15:10:16.000: W/ActivityManager(2098): mDVFSLock.acquire()
12-21 15:10:16.010: W/InputDispatcher(2098): channel ~ Consumer closed input channel or an error occurred.  events=0x8
12-21 15:10:16.010: D/InputDispatcher(2098): [drainOutboundQueueLocked] initialize cntPair(sender-receiver)
12-21 15:10:16.010: E/InputDispatcher(2098): channel ~ Channel is unrecoverably broken and will be disposed!
12-21 15:10:16.085: D/dalvikvm(2098): GC_FOR_ALLOC freed 821K, 47% free 22959K/43079K, paused 82ms
12-21 15:10:16.090: I/dalvikvm-heap(2098): Grow heap (frag case) to 25.390MB for 2903056-byte allocation
12-21 15:10:16.175: D/dalvikvm(2098): GC_FOR_ALLOC freed 15K, 41% free 25779K/43079K, paused 65ms
12-21 15:10:16.190: W/InputDispatcher(2098): Attempted to unregister already unregistered input channel
12-21 15:10:16.190: I/SurfaceFlinger(1904): id=2501 Removed MainActivity idx=2 Map Size=4
12-21 15:10:16.190: I/SurfaceFlinger(1904): id=2501 Removed MainActivity idx=-2 Map Size=4
12-21 15:10:16.190: D/KeyguardViewMediator(2098): setHidden false
12-21 15:10:16.190: W/SignalStrength(2098): getGsmLevel=2
12-21 15:10:16.190: W/SignalStrength(2226): getGsmLevel=2
12-21 15:10:16.190: W/SignalStrength(2226): getLevel=2 (SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 2)
12-21 15:10:16.190: W/SignalStrength(2226): getGsmLevel=2
12-21 15:10:16.190: W/SignalStrength(2226): getLevel=2 (SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 2)
12-21 15:10:16.190: W/InputDispatcher(2098): channel ~ Consumer closed input channel or an error occurred.  events=0x8
12-21 15:10:16.190: E/InputDispatcher(2098): channel ~ Channel is unrecoverably broken and will be disposed!
12-21 15:10:16.190: W/InputDispatcher(2098): Attempted to unregister already unregistered input channel
12-21 15:10:16.190: I/WindowManager(2098): WINDOW DIED Window{420e4858 XXXX.XXXXXXXXX.XXXXXXXXXXXXXXXX/XXXX.XXXXXXXXX.XXXXXXXXXXXXXXXX.XXXXXXXXXXXX paused=false}
12-21 15:10:16.190: D/STATUSBAR-NetworkController(2226): onSignalStrengthsChanged signalStrength=SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 2 level=2
12-21 15:10:16.190: I/WindowManager(2098): WIN DEATH: Window{426389d0 XXXX.XXXXXXXXX.XXXXXXXXXXXXXXXX/XXXX.XXXXXXXXX.XXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXX paused=false}
12-21 15:10:16.195: D/KeyguardViewMediator(2098): setHidden false
12-21 15:10:16.195: W/SignalStrength(2098): getLevel=2 (SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 2)
12-21 15:10:16.195: W/WindowManager(2098): Failed looking up window
12-21 15:10:16.195: W/WindowManager(2098): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@426977f0 does not exist
12-21 15:10:16.195: W/WindowManager(2098):  at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7807)
  • 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-16T06:03:30+00:00Added an answer on June 16, 2026 at 6:03 am

    This is how you are supposed to start the other activity.

    Intent intent = new Intent(yourclassname.this, textChooserView.class);
    startActivityForResult( intent, request_CodeText);
    

    instead of

      startActivityForResult(new Intent(
                "kurt.steveboss.textChooserView"),
                request_CodeText);
    

    And also on ActivityResult you should check if resultCode == RESULT_OK and data is different to null. This will help you from the null exception.

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

Sidebar

Related Questions

I'm having trouble showing the current image that I have captured using a 3rd
Anybody having trouble using AVFoundation with GC ON??? What I am experiencing is that
I am having trouble using nested ajax calls with selectors. I have a section
I am having trouble using JQuery with ASP.net. I have a HTML img ,
I'm having trouble using gsub correctly: Given this code: replace me.gsub(/replace me/, this \\0
I'm having trouble using contentEditable in FireFox 3. I have a problem where the
I'm having trouble using python function decorators in Google's AppEngine. I'm not that familiar
I am having trouble using JQuery to work with multiple radio button groups. The
I'm having trouble using an argument from my class in one of that class's
I am having trouble using system() from libc on Linux. My code is this:

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.