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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:19:21+00:00 2026-06-06T06:19:21+00:00

I am broadcasting an intent when a record button is clicked. a boolean variable

  • 0

I am broadcasting an intent when a “record” button is clicked. a boolean variable is passed, that shows whether the recording is started or not. The code to generate an intent is:

Intent recordIntent = new Intent(ACTION_RECORDING_STATUS_CHANGED);
recordIntent.putExtra(RECORDING_STARTED, getIsRecordingStarted());
sendBroadcast(recordIntent);

To test this code I have registered a receiver in test. The intent is received but the variable passed is not the same. If I debug the code, I can see that the value is same as it is sent, but when I get it, its not the same value.

@Test
public void pressingRecordButtonOnceGenerateStartRecordingIntent()
        throws Exception {
    // Assign
    AppActivity activity = new AppActivity();
    activity.onCreate(null);
    activity.onResume();

    activity.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent intent) {
            // Assert
            ShadowIntent shadowIntent = Robolectric.shadowOf(intent);
            assertThat(shadowIntent
                    .hasExtra(AppActivity.RECORDING_STARTED),
                    equalTo(true));
            Boolean expected = true;
            Boolean actual = shadowIntent.getExtras().getBoolean(
                    AppActivity.RECORDING_STARTED, false);
            assertThat(actual, equalTo(expected));

        }
    }, new IntentFilter(
            AppActivity.ACTION_RECORDING_STATUS_CHANGED));

    ImageButton recordButton = (ImageButton) activity
            .findViewById(R.id.recordBtn);

    // Act
    recordButton.performClick();
    ShadowHandler.idleMainLooper();

}

I have also tested against the actual intent instead of its shadow, but same result

  • 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-06T06:19:23+00:00Added an answer on June 6, 2026 at 6:19 am

    using the get() instead of getBoolean() worked for me.

    public void pressingRecordButtonOnceGenerateStartRecordingIntent()
            throws Exception {
        // Assign
        BreathAnalyzerAppActivity activity = new AppActivity();
        activity.onCreate(null);
        activity.onResume();
    
        activity.registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context arg0, Intent intent) {
                // Assert
                assertThat(intent
                        .hasExtra(AppActivity.RECORDING_STARTED),
                        equalTo(true));
                Boolean expected = true;
                Boolean actual = (Boolean)intent.getExtras().get(
                        AppActivity.RECORDING_STARTED);
                assertThat(actual, equalTo(expected));
    
    
            }
        }, new IntentFilter(
                AppActivity.ACTION_RECORDING_STATUS_CHANGED));
    
        ImageButton recordButton = (ImageButton) activity
                .findViewById(R.id.recordBtn);
    
        // Act
        recordButton.performClick();
        ShadowHandler.idleMainLooper();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have check against a boolean value if(!updating_questions) that is not working in my
I have a servlet that has a suspending method and a broadcasting one: @GET
Im Implementing a video broadcasting website. For that I planned to use silverlight player
I have a thread that is Broadcasting UDP packets. I have another thread that
OS X does not make it obvious that you might've left a screen sharing
I have an application that makes changes to some of the files in the
So I have some server broadcasting live data onto Named Pipe - \\.\pipe\TestChannel (from
I'm at the very early stages of a project requiring the broadcasting, using RTP,
I'm not exactly sure if the following scenario is possible. Using only UdpClient or
can my activity broadcast this intent from itself Intent i = new Intent(android.provider.Telephony.SMS_RECEIVED); sendBroadcast(i);

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.