1

I have the same problem others have had, but I can't get my code to work.

I have to java classes, Test.java and TestService.java and when I try to start Service or bind Service, I always get error listed above. I have tried the recommended standard solutions in here, but it didn't work. I will try to rename the java files and start a new project to see if that works as noted in here.

Then I saw this link by Vogella that I have to have a google user registered on the device. Is that what my problem is or am I confusing the errors (maybe 'intent.REGISTER' refers to something else).

Any suggestions on this will be greatly appreciated.

4.3. Register your application

Run your application, maintain your registered user and press the button. Check LogCat for the registration ID.

If you see the following message:

" Unable to start service Intent {act=com.google.android.c2dm.intent.REGISTER ... }: not found"

I've tried this, both on my phone and on the simulator.

Permissions:

<application android:icon="@drawable/gyroscopic" android:label="@string/app_name">
...
<activity android:name="Test"></activity>

<service android:name="TestService"></service>  
....
</application>
Community
  • 1
  • 1
sAguinaga
  • 638
  • 13
  • 31

2 Answers2

0

Try using the entire package code for your service, that's what I always do and it has always worked so far.

<service
    android:enabled="true"
    android:name="com.mobowski.appfrag.service.MusicService" >
</service>

Edit for starting / binding to the service.

I usually do this:

Starting the service

// This is in the onCreate of my main screen, but this would work in a button
startService(
            new Intent(this, Service.class));

In the service itself

You will use this when binding to the service

// Field of service
private final IBinder mBinder = new MyBinder(); 

// We return the binder class upon a call of bindService
    @Override
    public IBinder onBind(Intent arg0) {
        return mBinder;
    }

    public class MyBinder extends Binder {
        public MusicService getService() {
            return MusicService.this;
        }
    }

Binding to the service

For this I use several pieces of code that I took from an example once but they never failed me so far.

private ServiceConnection mConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName className, IBinder binder) {
            s = ((MusicService.MyBinder) binder).getService();
            Toast.makeText(this, "Connected", Toast.LENGTH_SHORT)
                    .show();
            // Little Toast to make sure we connected

        }

        public void onServiceDisconnected(ComponentName className) {
            s = null;
        }
    };

    void doBindService() {
        bindService(
            new Intent(this,
                    MusicService.class), mConnection,
            Context.BIND_AUTO_CREATE);

    }
Sander van't Veer
  • 5,930
  • 5
  • 35
  • 50
  • Like I said above, there are many related posts I've read (but I'm not saying that I read them all-- there are many) that suggest the same issue and it doesn't work (here is what I have in my manifest):`... ` – sAguinaga Dec 05 '11 at 23:53
  • Question. How are you trying to start / bind to the service? – Sander van't Veer Dec 06 '11 at 01:05
  • Binding to the services is done by:`Intent i = new Intent(AccelerometerService.class.getName()); bindService(i, _connection, Context.BIND_AUTO_CREATE); _isBound = true;` – sAguinaga Dec 06 '11 at 09:25
  • Starting the _service_ (when the button is clicked):`//Intent i = new Intent(AccelerometerService.class.getName()); Intent i = new Intent("edu.nd.bitstorm.AccelerometerService"); this.startService(i);` – sAguinaga Dec 06 '11 at 09:28
0

You need to provide the namespace in the name attribute in some form so:

<service android:name="edu.darts.neuromobi.TestService"></service>

or possibly:

<service android:name=".TestService"></service>
kabuko
  • 36,028
  • 10
  • 80
  • 93
  • Thank you @Vimal for fixing my post, I will do that next time. – sAguinaga Dec 05 '11 at 23:47
  • I've seen your suggestion in many of the other related posts, but I get the same result! I even tried to just take the service and the activity (that uses push-buttons to start the or bind to the service) and put them in a new project and with different file names with the same result. – sAguinaga Dec 05 '11 at 23:50