Sonya
Sonya

Reputation: 31

Unable to start service Intent in my Android program, what's wrong?

I'm a newbie and just start to learn Google Android right now

So I learn some code after I googled, but I don't know why it can't run well as wished. These program consists of two java files, AlarmService.java which contains an activity named AlarmService, and AlarmService_Service.java which contains a service named AlarmService_Service. Btw, I put it in the package com.AlarmService

Here where I created the intent in AlarmService activity (in AlarmService.java):

Intent intent = new Intent(AlarmService.this, AlarmService_Service.class);

mAlarmSender = PendingIntent.getService(AlarmService.this, 0,intent, 0);

Button button = (Button)findViewById(R.id.start_alarm); button.setOnClickListener(mStartAlarmListener);

And the code in AlarmService_Service is quite long, but anyway I also made a Toast to prompt me a text to ensure if this service is functioning or not.

It looks like the program failed to load AlarmService_Service. Nothing happen when I clicked the button, not even the Toast, and I saw this message in LogCat:

Unable to start service Intent {flg=0x4 cmp=com.AlarmService/.AlarmService_Service (has extras) }: not found

Honestly, I'm not familiar with Android so I keep wondering what is wrong with this code. Did I miss something? Or is it because that it couldnot find AlarmService_Service.class?

Thank you for your big help.

Upvotes: 3

Views: 4923

Answers (2)

ccheneson
ccheneson

Reputation: 49410

I am not too familiar with services (yet) but I can see that there is a <service> element in the Manifest.xml. Have you declared your AlarmService_Service in the AndroidManifest.xml ?

See more info here

Upvotes: 2

anon
anon

Reputation:

I think you should get your PendingIntent the following way:

PendingIntent mAlarmSender = PendingIntent.getService(AlarmService.this, 0, new Intent(AlarmService.this, AlarmService_Service.class), 0);

However see this source for a working example

Upvotes: 0

Related Questions