0

I have 2 launcher activities and 2 modes in my app. When start Activity_A app begin work in mode_A, and Activity_B start mode_B. App can work only in one mode at a given time. Activity_A and Activity_B init needed mode in onCreate()

I have next bad scenario:

  1. launch Activity_A, app init mode_A
  2. press home button, Activity_A go into background
  3. launch Activity_B, app init mode_B
  4. close Activity_B by back button
  5. launch Activity_A again -> it's restored (from 2 step), call onStart() and get a lot of exception, because app now in mode_B and Activity_A incompatible with mode_B.

I would like Activity_A clear from stack on step 3, and it would not be restored on step 5. How can I achive this?

Activitys in manifest:

<activity
    android:name="Activity_A"
    android:launchMode="singleTask"
    android:taskAffinity="Affinity_A">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>
<activity
    android:name="Activity_B"
    android:launchMode="singleTask"
    android:taskAffinity="Affinity_B" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Also I tried to use android:clearTaskOnLaunch and android:finishOnTaskLaunch with no result :(

Dmitry
  • 369
  • 4
  • 18

1 Answers1

0

I am not able to understand mode_A or mode_B.

but judging from your question title, you should try this question which mainly says:

In Activity A

  1. Declare a static field a like public static Activity a;

  2. instantiate in onCreate like a = this;

In Activity B

  1. Kill in onCreate like Activity_A.a.finsh();

If Application Exits after back press, you can override onBackPressed() and launch Activity from there.

Community
  • 1
  • 1
bharat
  • 105
  • 1
  • 1
  • 8