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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:52:23+00:00 2026-06-09T16:52:23+00:00

In Activity i have passed a value paramVal like this Intent srv = new

  • 0

In Activity i have passed a value paramVal like this

 Intent srv = new Intent(this, TestService.class);
    startService(srv);

     //Intent intent =new Intent("com.example.firstapplication.STARTACTIVITY"); 
     //intent.putExtra("myFirstKey", paramVal); 

    //intent.putExtra("myFirstKey", paramVal); 

    Bundle bundle = new Bundle();
    bundle.putCharSequence("myFirstKey", paramVal);
    intent.putExtras(bundle);

and in service I am retrieving a value like this

 @Override
  public void onStart(Intent intent, int startId) {
      // TODO Auto-generated method stub
      super.onStart(intent, startId);

      Bundle bundle = intent.getExtras();
      data = (String) bundle.getCharSequence("myFirstKey");

      System.out.println("data checking"+data);
     }

but i am getting null pointer exception for the line

data = (String) bundle.getCharSequence("myFirstKey");

in service

should i have to call onstart method in service somewhere. Please let me know where is the problem??

  • 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-09T16:52:24+00:00Added an answer on June 9, 2026 at 4:52 pm

    In your Activity:

    Intent lIntent = new Intent(this, TestService.class);
    lIntent.putExtra("myFirstKey", <your String param here>);
    startService(lIntent);
    

    In your Service:

    String lDataString = intent.getStringExtra("myFirstKey");
    

    As a sidenote:

    • please override onStartCommand() in your service, since onStart() is deprecated
    • it is not required to call super.onStartCommand() (or super.onStart() for that matter) when extending the Service class
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code in my first activity: Intent i = new Intent(this, OtherScreen.class);
I'd like to launch the camera activity and have it dump subsequent pictures into
I have an android program that launches an intent and passes a value to
I have an Activity with a Button which Intent is relative to how the
In my application I am using a List Activity in which I have passed
I have activity A, which launches activity B via an intent. Activity A has
I have an activity which has an array list ArrayList<String> array = new ArrayList<String>();
So I have a ListView on which I click to start new Activity called
I have an android activity that downloads content from the web. The activity have
I have Activity A with android:launchMode=singleTop in the manifest. If I go to Activity

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.