Activity won't start a service

Posted by Marko Cakic on Stack Overflow See other posts from Stack Overflow or by Marko Cakic
Published on 2012-09-17T18:13:47Z Indexed on 2012/09/18 3:38 UTC
Read the original article Hit count: 111

Filed under:
|
|

I m trying to start an IntentService from the main activity of y application and it won't start. I have the service in the manifest file. Here's the code:

MainActivity

public class Home extends Activity {
    private LinearLayout kontejner;
    IntentFilter intentFilter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        kontejner = (LinearLayout) findViewById(R.id.kontejner);
        intentFilter = new IntentFilter();

        startService(new Intent(getBaseContext(), HomeService.class));
    }
}

Service:

public class HomeService extends IntentService {

    public HomeService() {
        super("HomeService");
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Toast.makeText(getBaseContext(), "TEST", Toast.LENGTH_LONG).show();
        }
}

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.salefinder"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Home"
            android:label="@string/title_activity_home" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".HomeService" />
    </application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>

How can I make it work?

© Stack Overflow or respective owner

Related posts about android

Related posts about service