I've binded 2 android applications with an AIDL file. The Exchange between the A and B applications is like below:
- The A application connects to the B application through AIDL
interface
- A application calls a method of the B service
- B service returns a PendingIntent
- A application starts the PendingIntent
- When action is finished in the B application : back to the A
application
However, if the B application was launched before the exchange, user will be redirected to the last activity of the B application after calling the "finish()" method , not in the A application.
In my A application :
@Override
protected void onCreate(Bundle savedInstanceState) {
...
Intent i = new Intent();
i.setClassName(Utils.BILLING_PACKAGE,Utils.BILLING_INTERFACE);
try {
Boolean ret = bindService(i, mConnection, Context.BIND_AUTO_CREATE);
} catch (Exception e) {}
}
//ServiceConnection class
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder boundService) {
service = InBillingInterface.Stub.asInterface((IBinder) boundService);
Utils.debug(mContext, "connection status : "+ service );
}
public void onServiceDisconnected(ComponentName name) {
service = null;
}
};
...
//launch the second application
Bundle response = service.prepareForBillingService(data);
PendingIntent pIntent = response.getParcelable(Utils.RESPONSE_P_INTENT);
try {
Intent in = new Intent();
in.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
pIntent.send(mContext, 0, in);
} catch (PendingIntent.CanceledException e) {
Utils.error("Sending contentIntent failed:" + e.getMessage());
}
I've tried to set android:launchMode to singleTask or singleTop in the A application manifest file but problem remains same. As you can see, I also put a "FLAG_ACTIVITY_MULTIPLE_TASK" flag when sending activity.
Code in my B application:
Creating the PendingActivity
public class InBillingService extends Service {
private static final String TAG = "my tag";
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "Welcome!");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Byebye!");
}
/**
* Method for AIDL interface
*/
@Override
public IBinder onBind(Intent arg0) {
return new InBillingInterface.Stub() {
//a method that return a pendingIntent
@Override
public Bundle prepareForBillingService(String appId,String encryptedData) throws RemoteException {
Bundle bundle = new Bundle();
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setClass(InBillingService.this, xx.xxx.activities.BilingActivity.class);
intent.putExtra(Consts.PENDING_INTENT_INFO, result);
PendingIntent pendingIntent = PendingIntent.getActivity(InBillingService.this, 0, intent, 0);
bundle.putParcelable(Consts.PENDING_INTENT, pendingIntent);
return bundle ;
}
};
}
In the BillingActivity
//if no problems
finish()
Thank you for reading !
---update
My manifest file for the B activity :
<activity
android:name=".activities.BillingActivity"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTask"
android:label="@string/title_activity_billing" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>