Here:
Intent serviceIntent = new Intent(bgservice.class.getName());
Passing a string to the Intent constructor to create an Intent to start the service. The Intent constructor accepts String as the name of the action we added to AndroidManifest.xml .
<service android:enabled="true" android:name=".bgservice"> <intent-filter > <action android:name="com.microapple.googleplace.bgservice" /> </intent-filter> </service>
Now use com.microapple.googleplace.bgservice as the name of the action to create the Intent:
Intent serviceIntent = new Intent("com.microapple.googleplace.bgservice"); serviceIntent.putExtra("UserID", "123456"); this.startService(serviceIntent);
OR
Use an Intent constrictor that takes a context as the first parameter and the name of the component that we want to run as the second parameter:
Intent serviceIntent = new Intent(this,bgservice.class); serviceIntent.putExtra("UserID", "123456"); this.startService(serviceIntent);
And also use the same key that is used to add data to the Intent, currently adding the value using the UserID , but trying to get the value using the UserID key
source share