Hi,

I know there are many posts around the issue I am facing but I havent
been able to see any yet which addresses my issue.

This is what I am doing:

1. Create 2 apks. (1 with an activity - lets call it F1App and 2nd
with a service - F1Service)
2. Both APKs have same sharedUserId and same android.process and are
signed with the same key - I have been able to confirm that the 2 are
now running in the same process.
3. From App 1 I bind to F1Service
4. Bind returns successfully but I am unable to access the classes
using the binder. The same code works fine in the sample code but the
2 there are in the same apk.

Here is the F1App code.

package f1.f1;

import com.fusionone.F1Service;


import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class F1App extends Activity {
    private boolean mIsBound;
    public F1Service mBoundService;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout);

        // Watch for button clicks.
        Button button = (Button)findViewById(R.id.bind);
        button.setOnClickListener(mBindListener);
        button = (Button)findViewById(R.id.unbind);
        button.setOnClickListener(mUnbindListener);
    }

    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className,
IBinder service) {
            // This is called when the connection with the service has
been
            // established, giving us the service object we can use to
            // interact with the service.  Because we have bound to a
explicit
            // service that we know is running in our own process, we
can
            // cast its IBinder to a concrete class and directly
access it.
                Log.d("Got Binder", "Got Binder" + service);
                mBoundService =
((F1Service.LocalBinder)service).getService();
        }

        public void onServiceDisconnected(ComponentName className) {
            // This is called when the connection with the service has
been
            // unexpectedly disconnected -- that is, its process
crashed.
            // Because it is running in our same process, we should
never
            // see this happen.
            mBoundService = null;
            Toast.makeText(F1App.this,
R.string.local_service_disconnected,Toast.LENGTH_SHORT).show();
        }
    };

    private OnClickListener mBindListener = new OnClickListener() {
        public void onClick(View v) {
            // Establish a connection with the service.  We use an
explicit
            // class name because we want a specific service
implementation that
            // we know will be running in our own process (and thus
won't be
            // supporting component replacement by other
applications).
                Intent toSend = new Intent("com.fusionone.F1Service");
                bindService(toSend, mConnection, Context.BIND_AUTO_CREATE);
                mIsBound = true;
        }
    };

    private OnClickListener mUnbindListener = new OnClickListener() {
        public void onClick(View v) {
            if (mIsBound) {
                // Detach our existing connection.
                unbindService(mConnection);
                mIsBound = false;
            }
        }
    };
}




Now the F1Service looks like this:
public class F1Service extends Service {
    private NotificationManager mNM;

    /**
     * Class for clients to access.  Because we know this service
always
     * runs in the same process as its clients, we don't need to deal
with
     * IPC.
     */
    public static class LocalBinder extends Binder {
        public static F1Service myServiceObj;
        LocalBinder(F1Service x){
                myServiceObj = x;
        }
        public F1Service getService() {
            return myServiceObj;
        }
    }

    @Override
    public void onCreate() {
        mNM =
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        // Display a notification about us starting.  We put an icon
in the status bar.
        showNotification();
    }

    @Override
    public void onDestroy() {
        // Cancel the persistent notification.
      //  mNM.cancel(R.string.local_service_started);

        // Tell the user we stopped.
        //Toast.makeText(this, R.string.local_service_stopped,
Toast.LENGTH_SHORT).show();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return mBinder;
    }

    // This is the object that receives interactions from clients.
See
    // RemoteService for a more complete example.
    private final IBinder mBinder = new LocalBinder(this);

    /**
     * Show a notification while this service is running.
     */
    private void showNotification() {
    }
}


The error I get is during install time:

I/ActivityManager(  563): Start proc f1process.myprocess for activity
f1.f1/.F1A
pp: pid=1556 uid=10024 gids={}
D/dalvikvm( 1548): LinearAlloc 0x0 used 676436 of 4194304 (16%)
I/jdwp    ( 1556): received file descriptor 10 from ADB
D/ddm-heap( 1556): Got feature list request
W/ActivityThread( 1556): Application f1.f1 is waiting for the debugger
on port 8
100...
I/System.out( 1556): Sending WAIT chunk
I/dalvikvm( 1556): Debugger is active
I/System.out( 1556): Debugger has connected
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): waiting for debugger to settle...
I/System.out( 1556): debugger has settled (1433)
E/dalvikvm( 1556): Could not find class 'com.fusionone.F1Service
$LocalBinder', r
eferenced from method f1.f1.F1App$1.onServiceConnected
W/dalvikvm( 1556): VFY: unable to resolve check-cast 13 (Lcom/
fusionone/F1Servic
e$LocalBinder;) in Lf1/f1/F1App$1;
W/dalvikvm( 1556): VFY:  rejecting opcode 0x1f at 0x0018
W/dalvikvm( 1556): VFY:  rejected Lf1/f1/F1App$1;.onServiceConnected
(Landroid/c
ontent/ComponentName;Landroid/os/IBinder;)V
W/dalvikvm( 1556): Verifier rejected class Lf1/f1/F1App$1;




I would really appreciate all help on this!

Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to