I have spent 6 hours trying to solve this issue without success.

I have 2 applications which communicate through a AIDL service. Here is the source code:

Application A :

protected void onCreate(Bundle savedInstanceState) {

...
Intent i = new Intent();
i.setClassName("xxx.service","xx.service.MyService");
try {
   Boolean ret = bindService(i, mConnection, Context.BIND_AUTO_CREATE);
} catch (Exception e) {
   Utils.error("application not installed");
}

...

button1.setOnClickListener(this);

//service connection instance
private ServiceConnection mConnection = new ServiceConnection() {
   public void onServiceConnected(ComponentName name, IBinder boundService) {
      service = BillingInterface.Stub.asInterface((IBinder) boundService);
      Utils.debug(mContext, "connection to service !");
      }

      public void onServiceDisconnected(ComponentName name) {
      service = null;
      }
};
...

//when clicking button, method of service is called
public void onClick(View arg0) {

   bundle = null ;
   bundle = service.myMethod(myId);

   PendingIntent pIntent = bundle.getParcelable(Utils.RESPONSE_P_INTENT);

   try {
    Intent in = new Intent();
    pIntent.send(mContext, 0, in);
   } catch (PendingIntent.CanceledException e) {
    Utils.error("Sending contentIntent failed:" + e.getMessage());
   }
}

}

public void onDestroy(){
super.onDestroy();
unbindService(mConnection);
mConnection = null;
}

Service in Application B returns a Bundle which contains a PendingIntent:

@Override
public IBinder onBind(Intent arg0) {
return new BillingInterface.Stub() {

   @Override
   public Bundle myMethod(String id) throws RemoteException {

      //Service class implements parcelable class
      DB.domains.Service result = dao.getServiceDetails(appId);

      Intent intent = new Intent(); 
      intent.setClass(BillingService.this, xx.appli.test.class);
      intent.putExtra(Consts.PENDING_INTENT_INFO, result);


      PendingIntent pendingIntent;                  
      pendingIntent = PendingIntent.getActivity(BillingService.this, 0, intent, 0);                         

      bundle.putParcelable(Consts.PENDING_INTENT, pendingIntent);

      return bundle; 

   }
};
}

In my Manifest file :

<service
    android:name=".service.BillingService"
    android:enabled="true"
    android:exported="true"
    android:process=":remote" >
    <intent-filter>
        <action android:name=".service.BillingInterface.aidl" />
    </intent-filter>
</service>

Activity launched with the pendingIntent:

public void onCreate(Bundle savedInstanceState) {
...
Bundle bundle = getIntent().getExtras();
serviceInfo = bundle.getParcelable(Consts.BUNDLE_APPLI);

//Data processing
...

finish()

}

Data passed as parameters in the PendingIntent (Consts.PENDING_INTENT_INFO) are different for each call. However, after the first call, data in activity class (serviceInfo) are identical every time. Data seems to persist somewhere.

I've checked all the below points:

  • Activity is closed with finish () after data processing
  • Connection to the service is closed in the OnDestroy() method
  • "result" object (in the service) is instantiate when method is called
  • "bundle" object is intantiate before calling service

I am in a hurry and would appreciate your precious help.

Thank you for reading !

有帮助吗?

解决方案

I've fixed it, thank you !

I've changed the below line :

pendingIntent = PendingIntent.getActivity(BillingService.this, 0, intent, 0);  

to

pendingIntent = PendingIntent.getActivity(BillingService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);  

Thank you for your help.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top