I've binded 2 android applications with an AIDL file. The Exchange between the A and B applications is like below:
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>
In order to return to Application A after BillingActivity finishes in Application B, do the following:
In the manifest file for Application B, make the BillingActivity launchMode singleInstance like this:
<activity
android:name="xx.xxx.activities.BillingActivity"
android:launchMode="singleInstance" >
</activity>
Per this link:
The "singleTask" and "singleInstance" modes also differ from each other in only one respect: A "singleTask" activity allows other activities to be part of its task. It's always at the root of its task, but other activities (necessarily "standard" and "singleTop" activities) can be launched into that task. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a different task — as if FLAG_ACTIVITY_NEW_TASK was in the intent.