Yuval Fatal
Yuval Fatal

Reputation: 1

Why my application crash? I am using service

I made a service that every 5 second he put on the screen a TAG (I think this is the name of this). When I make a boot it needs to put the TAG on the screen but he says that the app crashed. Why? The code: Android Manifest:

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <receiver android:name="com.YuvalFatal.MyBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:enabled="true" android:name="com.YuvalFatal.MyService"/>

BroadcastReceiver:

  package com.YuvalFatal.ineedhelp;

import java.util.Timer;
import java.util.TimerTask;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyBroadcastreceiver extends BroadcastReceiver {

@Override
public void onReceive(final Context arg0, Intent arg1) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public void run() {
            Intent startServiceIntent = new Intent(arg0, MyService.class);
            arg0.startService(startServiceIntent);
        }
    }, 0, 5000);
}
}  

IntentService:

package com.YuvalFatal.ineedhelp;

import android.app.IntentService;
import android.content.Intent;
import android.util.Log;


public class MyService extends IntentService {

private static final String TAG = "com.YuvalFatal.ineedhelp";

public MyService(String name) {
    super(name);
    // TODO Auto-generated constructor stub
}

@Override
protected void onHandleIntent(Intent intent) {
    // TODO Auto-generated method stub
    Log.i(TAG, "Intent Service started");
}

}

Upvotes: 0

Views: 654

Answers (1)

Artem Zinnatullin
Artem Zinnatullin

Reputation: 4447

I think (yep, I am magician and have great intuition :) your Service constructor should be default:

public class MyService extends IntentService {
    ...

    public MyService() { // Default constructor! Without params!
        super("MyService"); // Or another string
    }

...
}

Other code looks normal

Upvotes: 3

Related Questions