Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving One Instance Of Activity
    primarykey
    data
    text
    <p>I have a problem with Activity navigation and the back stack and I was hoping you could clear it up for me.</p> <p><strong>The Problem</strong></p> <p>Root Activity >>> SecondActivity >> HomeButton </p> <p>This then takes me to the home page and from there I select...</p> <p>Gmail >> Message >> Open attachment in my application >> ImportActivity >> RootActivity</p> <p>The outcome is a new task being started and another instance of my application being used. This is unacceptable as I don't want two separate tasks running I only want one.</p> <p><strong>The Desired Outcome</strong></p> <p>What I want to happen is when the user opens the attachment and <strong>ImportActivity</strong> finishes what its doing (it has <code>android:noHistory</code> set to true) and calls <code>startActivity(intent)</code>, <code>RootActivity</code> is started, but keeping only one instance and the rest of the activities on top of it in the original task (in this case <code>SecondActivity</code>)are removed.</p> <p>The reason I want this is if the user navigates out of my application after importing the file and then touches the app icon it loads the first task with its back stack and I have two tasks running in which the user can be in two different parts of my application at once.</p> <p><strong>What I have tried</strong></p> <p>I have played around with the launch mode but none of them really give me the functionality that I need.</p> <p>Launch Modes I have tried..</p> <p><em>android:launchMode="singleTask"</em> - this just started the root activity again each time it was launched. Even if the user pressed the home button inside my application and touched the App icon the back stack was destroyed.</p> <p><em>android:launchMode="singleInstance</em> = doesn't allow any other activites to run in the task.</p> <p>Also when calling the intent to start the <code>RootActivity</code> I have used the following to no avail.</p> <pre><code>Intent i = new Intent(ImportActivity.this,TrackingActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); </code></pre> <p>Is it possible to do what I want?</p> <p><strong>Thanks in advance</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload