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

  • Home
  • SEARCH
  • 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 6040251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:29:13+00:00 2026-05-23T06:29:13+00:00

My main activity has three check boxes in it. I want to be able

  • 0

My main activity has three check boxes in it. I want to be able to pass whether or not these check boxes are checked to a service when the “submit” button is pressed. Here is my code:

public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent start_service = new Intent();
        start_service.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        start_service.setClass(getApplicationContext(), FollowService.class);

        if( box1.isChecked() ){
            boxes[0] = 1;
        }
        if( box2.isChecked() ){
            boxes[1] = 1;
        }
        if( box3.isChecked() ){
            boxes[2] = 1;
        }

        start_service.putExtra("com.mypackage.boxes", selections);
        box1.setChecked(false);
        box2.setChecked(false);
        box3.setChecked(false);
        getApplicationContext().startService(start_service);
    }

I then try to access this array that I am attempting to pass to the service inside of my onStartCommand by doing the following:

public int onStartCommand(Intent intent, int flags, int startID){
    try {
        Bundle selections = intent.getExtras();
        int [] boxes = selections.getIntArray("boxes");

        if( boxes[0] == 1 ){
            // do something
        }
        if( boxes[1] == 1 ){
            // do something             
        }
        if( boxes[1] == 1 ){                                 // do something
        }

        checkWebsite();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return START_STICKY;
}

My application will start up and doesn’t force close on me when I press the “submit” button, but I am getting a system.err message in LogCat.

Here is the LogCat error message that I have received when I try to start my service.

06-19 04:20:51.514: WARN/System.err(300): java.lang.NullPointerException
06-19 04:20:51.536: WARN/System.err(300):     at com.mypackage.FollowService.onStartCommand(FollowService.java:60)
06-19 04:20:51.536: WARN/System.err(300):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
06-19 04:20:51.544: WARN/System.err(300):     at android.app.ActivityThread.access$3600(ActivityThread.java:125)
06-19 04:20:51.544: WARN/System.err(300):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
06-19 04:20:51.554: WARN/System.err(300):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 04:20:51.554: WARN/System.err(300):     at android.os.Looper.loop(Looper.java:123)
06-19 04:20:51.554: WARN/System.err(300):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-19 04:20:51.574: WARN/System.err(300):     at java.lang.reflect.Method.invokeNative(Native Method)
06-19 04:20:51.574: WARN/System.err(300):     at java.lang.reflect.Method.invoke(Method.java:521)
06-19 04:20:51.574: WARN/System.err(300):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-19 04:20:51.574: WARN/System.err(300):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-19 04:20:51.584: WARN/System.err(300):     at dalvik.system.NativeStart.main(Native Method)
  • 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-05-23T06:29:14+00:00Added an answer on May 23, 2026 at 6:29 am

    follow below steps

    1) make a class file name first.java and write below code

    package com.example.bundle;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    
    public class first extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Intent intent = new Intent(this, second.class);
            int[] arr = new int[3];
            arr[0]=0;
            arr[1]=1;
            arr[2]=2;
            Bundle bundle = new Bundle();
            bundle.putIntArray("arr", arr);
            intent.putExtras(bundle);
            startService(intent);
        }
    }
    

    2) make a service name second.java and put below code

    package com.example.bundle;
    
    import android.app.Service;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.IBinder;
    import android.widget.Toast;
    
    public class second extends Service {
    
        @Override
        public IBinder onBind(Intent intent) {
            return null;
        }
    
        @Override
            public int onStartCommand(Intent intent, int flags, int startId) {
             Bundle bundle = intent.getExtras();
                int[] arr = bundle.getIntArray("arr");
                Toast.makeText(second.this, "" + arr[0] + " " + arr[1] + " " + arr[2], Toast.LENGTH_LONG).show();
                return super.onStartCommand(intent, flags, startId);
            }
    }
    

    3) and menifest like this

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.bundle"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".first" android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <service android:name=".second" android:label="@string/app_name">
    
            </service>
        </application>
    
    
    </manifest> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any View has a parent. If I check the main layout of an activity,
My app has three main activity. Splash Activity Login Activity Menu Activity When I
I am making an android application which has a main activity and several other
I have three tabs that each has its own Activity. The tabs are as
I have three activities in my android app. First activity is main application screen
I have a project which has gui consisting of three buttons.Now one of these
My application starts from an Main activity and this main activity has its own
I have Application that contains main Activity, Service and several Threads run on this
In the main activity of my app, it has the user enter their Name
I'm creating android app that has table layout for the main activity, and that

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.