Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Create a single task with multiple applications' activities (Lauchmode issue)

I don't know how to tackle this Android issue. In few words, the flow between my 2 applications is as below :

Flow

  1. Bind Application A to a service in Market application (AIDL)
  2. Register a BroadcastReceiver and call a service method that returns a pendingIntent.
  3. Launch PendingIntent (contains BillingActivity instance).
  4. Start PaymentActivity with "startActivityForResult()".
  5. Do some stuffs, terminate (finish() ).
  6. in onActivitiyResult() method, send a Broadcast and terminate.
  7. Get Broadcast informations.

Flow between my 2 applications

Issue :

I want to create a task with the below components :

  • Top1Activity(Application A)
  • BillingActivity (Market Application)
  • PaymentActivity (Market Application)

foreground and background tasks for Android

I tried to change the BillingActivity + PaymentActivity "launchMode" :

singleInstance

A new task is created for both of them. When pressing return button (or calling finish() method), user is redirected as expected to the previous activity. Problem: "StartActivityForResult" cannot be use between multiple tasks (onActivityResult is called immediately ).

SingleTask

When pressing return button (or calling finish() method) in BillingActivity, user is redirected to the Top2Activity (which was in the background task).

I 've lost more than 48 hours trying to solve it. I would appreciate your help. I can post code if needed.

Thank you

----------- EDIT 2015-02-02

Following the advice of David, i removed all special launch modes :

TOP2Activity(background):

<activity
    android:name=".activities.MainActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/title_activity_main"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="stateAlwaysHidden|adjustPan" >
    <meta-data
        android:name="android.app.searchable"
        android:resource="@xml/searchable" />

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="xxx" />
        <data android:host="xxx" />
    </intent-filter>
</activity>

My Top1Activity(Foreground):

<activity
    android:name="activities.MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

BillingActivity(Foreground):

<activity
    android:name=".activities.BillingActivity"
    android:configChanges="orientation|keyboardHidden"
    android:excludeFromRecents="true"
    android:label="@string/title_activity_billing"

    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
    </intent-filter>
</activity>

PaymentActivity:

<activity
    android:name=".activities.PaymentActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/title_activity_payment"
    android:screenOrientation="portrait"

    android:windowSoftInputMode="stateHidden" >
</activity>

AIDL Service returning pendingIntent:

Intent intent = new Intent();
intent.setClass(InBillingService.this, jp.xxx.activities.BillingActivity.class);
intent.putExtra(Consts.PENDING_INTENT_INFO, result);
intent.putExtra(Consts.RESULT_KEY, nextSession);


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

bundle.putParcelable(Consts.PENDING_INTENT, pendingIntent);

When pressing back button from BillingActivity (or PaymentActivity), I am still redirected to the Top2Activity...

No idea ? Thank you

like image 799
johann Avatar asked Jan 30 '15 05:01

johann


1 Answers

Add android:taskAffinity="" to the <activity> defninitions for bothBillingActivityandPaymentActivity`.

like image 73
David Wasser Avatar answered Sep 23 '22 14:09

David Wasser