I’ve got an IntentService that I want to start upon onCreate. It’s a fire and forget that makes a call to a website and then (possibly) starts a download through downloadmanager. I don’t believe that my service is being started, because I don’t see any Log statements from it. I’ve got the service in my manifest, same package as main. It also does not show up in my logcat (another thread said it should).
onCreate:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Intent heartbeat = new Intent(this, Heartbeat.class);
startService(heartbeat);
}
*I’ve also tried this.startService(heartbeat); and it also did not work.
manifest:
<application
android:debuggable="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<service android:name=".Heartbeat" android:enabled="true"/>
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
*with or without android:enabled flag makes no difference
start of IntentService:
public class Heartbeat extends IntentService
{
public Heartbeat()
{
super("Heartbeat");
Log.v("SUPER", "SUPER");
}
@Override
protected void onHandleIntent(Intent intent)
{
Log.v("HERE", "HERE");
//do other stuff
Neither of these log statements show up in console/logcat, and my service never hits the web server (this code was previously in an asynctask and was functioning). Any ideas on what I’m doing wrong?
Edit – I do see a warning from tag ActivityManager in my all messages stating “Unable to start service Intent { act=com.example.vs_1.Heartbeat }: not found”. However, nearly every suggestion I’ve seen on that message has been to put in manifest in the application tag, which I’ve already done.
Ah, the plot thickens!
“Unable to start service” is an error, even though it’s marked as a warning.
It occurs because the system can’t find a class that has the name that’s listed. In this case,
it’s com.example.vs_1.Heartbeat.
To be sure you have that class, you need a file Hearbeat.java that contains
package com.example.vs_1;
public class Heartbeat extends IntentService…
In your manifest, if your element contains the attribute
package=”com.example.vs_1″, then you can say
Note the period (“.”) before “Heartbeat”.
If you’re using another value for “package”, then you have to say
/com.example.vs_1.Heartbeat” where is the value of “package”.
It should be clear from this that you should choose a single main package name for your classes, and use the same name for the “package” value.