简体   繁体   中英

My Android service does not start

My service does not start.

I used the following onCreate method within my service:

public void onCreate(Bundle savedInstanceState){

        wsConnection = new WSConnection();
        handler = new Handler();
        Bundle b = savedInstanceState;
        this.dbManager = b.getParcelable("object");

        super.onCreate();
        Log.i("prova","servizio attivato");
        TimerTask task = new TimerTask(){
            public void run(){


                FindPendingData();
            }

        };
        timer = new Timer();
        //timer.schedule(task, cal.getTime());
        timer.schedule(task, 0, 30000);
    }

while, the following code starts my service:

        Intent intent = new Intent(this, myService.class);
        intent.putExtra("object", myObject);
        startService(intent);

object extends Object and implements Parcelable

I also declare in the Manifest:

<service android:name="myPackage.myService" /> 

Any idea Where the problem may be?

EDIT : I tried removing the Bundle parameter and now the service starts! But I don't understand why! Someone can help me?

use onStartCommand(Intent, int, int) or onStart() instead of onCreate of Service for getting Intent data as:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
      // get intent data here
    return START_STICKY;
}

as in comment OP says :

no error. I always use this code for starting service and usually this works good

but if we see in doc onCreate() not take any parameter if you are overriding it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM