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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:26:03+00:00 2026-05-26T18:26:03+00:00

I’ve really tried to get through the intent.putExtra() and getIntent().getExtras() and apply them to

  • 0

I’ve really tried to get through the intent.putExtra() and getIntent().getExtras() and apply them to one of the SimpleService tutorials. I know a lot of people have already asked “why is bundle extras always null?” I promise I tried to hack through the answers I found here for several hours before I considered posting but I don’t think I’m advanced enough to really understand what it is I must be doing wrong with the minor snippets people are posting. As such I put in the full code of my activity and my service.

I think my issue is the that my starting intent (the one I create in my activity) doesn’t exist in the context of my service. I wonder if maybe I’m using Intents in the wrong direction/purpose entirely? I did try an intent.putExtra in my service, to try to send a string the other direction, but those extras are always null, too. So at the risk of repetition, why is bundle extras always null? How do I make a single intent that exists both in the context of my activity and my service?

I should note that the code as displayed below obviously will have a null extras because I’ve commented out a few of my attempts to .getExtras() that have failed. I deleted the rest for the sake of cleanliness.

EDIT: The answer thanks to the replies, in code for the sake of those who have also been Googling for hours. Put this in your service (please note that the return START_REDELIVER_INTENT may be wrong):

@Override
public int onStartCommand( Intent intent , int flags , int startId )
{
      super.onStartCommand(intent, flags , startId);

      extras = intent.getExtras();

          //just checking
      if( extras != null )
      Toast.makeText(this,extras.getString("extratoservice"), Toast.LENGTH_SHORT).show();

      return START_REDELIVER_INTENT;

}

My activity (based on Sai Geetha’s blog):

package com.example.BroadcastIntent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class BroadcastIntentActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button start = (Button)findViewById(R.id.buttonStart);
    start.setOnClickListener(startListener);

    Button stop = (Button)findViewById(R.id.buttonStop);
    stop.setOnClickListener(stopListener);   

    //the intent I'm using to start and stop the service -- the extras don't go anywhere....
    intent = new Intent(BroadcastIntentActivity.this,BroadcastService.class);     
    intent.putExtra("extratoservice", "if you can read this, it made it to the service" );

}

Boolean serviceRunning;
Intent intent;

//Clicks from Geetha's Blog
private OnClickListener startListener = new OnClickListener() {
     public void onClick(View v){

         startService(intent);
         serviceRunning = true;
     }                 
};

private OnClickListener stopListener = new OnClickListener() {
    public void onClick(View v){

         try
         {
             stopService(intent);
             serviceRunning = false;                
         }
         catch( Exception e)
         {
             Toast.makeText(getApplicationContext(), "Service was not running...",Toast.LENGTH_SHORT).show(); 
         }
     }                 
 };

}

And this is my service:

package com.example.BroadcastIntent;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

public class BroadcastService extends Service{

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub

    //extras = arg0.getExtras();    <-- this has null extras, too...

    return null;
}

Bundle extras;

@Override
public void onCreate() {
      super.onCreate();

      // extras = getIntent().getExtras();   <-- this is undefined?

      if( extras == null )
      Toast.makeText(this,"Service created... extras still null", Toast.LENGTH_SHORT).show();
      else
      Toast.makeText(this,extras.getString("extratoservice"), Toast.LENGTH_SHORT).show();

}

@Override
public void onDestroy() {
      super.onDestroy();
      Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_SHORT).show();

}
}
  • 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-26T18:26:04+00:00Added an answer on May 26, 2026 at 6:26 pm

    you need to look at the onStartCommand() function (I’m not at a desktop so I can’t conveniently link to the javadoc). This will receive the intent you passed and your extras should be available there.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am reading a book about Javascript and jQuery and using one of the

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.