我已經用AIDL文件綁定了2個android應用程序。 A和B的應用程序之間的交換是象下面這樣:Android:在singleTop/singleTask模式下綁定應用程序(AIDL)
- 該A應用程序通過AIDL 接口
- 甲應用程序連接到B應用程序調用乙服務的方法
- 乙服務返回的PendingIntent
- 甲應用啓動的PendingIntent
- 當動作結束在B應用:回甲 應用
但是,如果B應用程序在交換之前啓動,則在調用「finish()」方法後,用戶將被重定向到B應用程序的最後一個活動,而不是在A應用程序中。
在我的一個應用程序:
@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());
}
我試過設置的Android:launchMode到singleTask或singleTop在一個應用程序清單文件,但問題仍然相同。正如你所看到的,我在發送活動時也放了一個「FLAG_ACTIVITY_MULTIPLE_TASK」標誌。
代碼在我的B級應用:
創建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 ;
}
};
}
在BillingActivity
//if no problems
finish()
感謝您的閱讀!
---更新爲B活性
我的清單文件:
<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>
不知道解決我的問題嗎?我很着急,我會感謝您的幫助。謝謝 – johann 2013-03-21 01:17:53
B應用程序不是服務嗎? AIDL通常用作客戶端/服務器模型中的IPC。所以我假設應用程序A是客戶端,應用程序B是服務器形式的服務器。爲什麼應用程序B有與之相關的活動? – Luis 2013-04-01 04:27:44
B應用程序包含一個爲B應用程序中的活動返回pendingIntent的服務。我的解釋清楚了嗎? – johann 2013-04-01 04:46:10