Question

J'ai un fichier AIDL défini comme suit:

package com.erbedo.callalert;

interface RemoteCallAlert {
    void notifyCallEnded();
}

Le service est:

package com.erbedo.callalert;

public class CallAlert extends Service {

    Filter callListener;

    private final RemoteCallAlert.Stub mBinder = new RemoteCallAlert.Stub() {
        @Override
        public void notifyCallEnded() throws RemoteException {
                  // TODO
        }
        };

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

    @Override
    public void onCreate() {
        super.onCreate();
        Toast.makeText(this, "CallAlert Created", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "CallAlert Destroyed", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        Toast.makeText(this, "CallAlert Started", Toast.LENGTH_LONG).show();
        callListener = new Filter();
        TelephonyManager tm = 
            (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
        tm.listen(this.callListener, PhoneStateListener.LISTEN_CALL_STATE);
    }

    public void callEnded() {
          // TODO
    }
}

et l'activité qui doit se lier au service est la suivante: com.erbedo.callalert de colis;

public class DummyStart extends Activity {

    Filter callListener;
    RemoteCallAlert mService;

    private ServiceConnection mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className,
                IBinder service) {
            Log.d("CONNECT","OK");
        }

        public void onServiceDisconnected(ComponentName className) {

        }
    };

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout l = new LinearLayout(this);
        setContentView(l);
        this.startService(new Intent(this, CallAlert.class));
    }   
}

Le onServiceConnected est pas appelé. Est-ce que je manque quelque chose évidente?

Était-ce utile?

La solution

startService() n'utilise pas ServiceConnection. bindService() fait.

Autres conseils

Intent intent = new Intent(CallAlert.class.getName());
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
  
    

Le onServiceConnected est pas appelé.

  

Pour la liaison avec le service que vous avez besoin d'appeler bindService (). Il fournit la connexion de la persistance, et après établissement de la connexion onServiceConnected () est appelée.

Deuxième point: -  Si vous utilisez le mécanisme IPC AIDL alors je pense que vous avez besoin de la communication entre les deux processus diff / Application. Ici, vous devez avoir la même copie du fichier .aidl dans les deux côtés de service et d'activité dans la même PAQUET. Ensuite, vous devez modifier peu de votre côté d'activité ..

vous pouvez trouver ici

http://www.zestofandroid.blogspot.com/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top