Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I learned a lot from the Android docs:</p> <p><a href="http://developer.android.com/guide/components/tasks-and-back-stack.html" rel="nofollow noreferrer">Tasks and Back Stack</a></p> <p><a href="http://developer.android.com/design/patterns/navigation.html" rel="nofollow noreferrer">Navigation with Back and Up</a></p> <p><a href="http://developer.android.com/design/patterns/app-structure.html" rel="nofollow noreferrer">Application Structure</a></p> <p>Here is some highlight:</p> <blockquote> <p>A task is a collection of activities that users interact with when performing a certain job. The activities are arranged in a stack (the "back stack"), in the order in which each activity is opened.</p> <p>When the current activity starts another, the new activity is pushed on the top of the stack and takes focus. The previous activity remains in the stack, but is stopped. When an activity stops, the system retains the current state of its user interface. When the user presses the Back button, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored). Activities in the stack are never rearranged, only pushed and popped from the stack—pushed onto the stack when started by the current activity and popped off when the user leaves it using the Back button.</p> </blockquote> <p>It means when your application <a href="https://stackoverflow.com/a/867828/1365960">pick up a contact</a>, the activity stack in the task might be:</p> <p>| Activity A in Contacts |</p> <p>| Activity B in Your App |</p> <p>| Activity C in other app|</p> <blockquote> <p>When the user leaves a task by pressing the Home button, the current activity is stopped and its task goes into the background. The system retains the state of every activity in the task. If the user later resumes the task by selecting the launcher icon that began the task, the task comes to the foreground and resumes the activity at the top of the stack.</p> </blockquote> <p>Even if the user exits the Contacts app while it was open and re-launched the app from the launcher menu or recent app list, the activity stack is still like the one we see above. The only possibility that may make your acitity start from another task is another app(might be a launcher app) that start the main activity in a new task by startActivity flags, which is a rare case. In this rare case, you can simply check the uid of the app who start your activity by <a href="http://developer.android.com/reference/android/os/Binder.html#getCallingUid%28%29" rel="nofollow noreferrer">Binder.getCallinguid()</a> to differentiate it. </p> <p>EDIT based on comments:</p> <p>You may check if activity was opened from history by <a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY" rel="nofollow noreferrer">FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY</a>:</p> <pre><code>if ((getIntent().getFlags() &amp; Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0){ }else{ } </code></pre> <p>You can also look into:</p> <p><a href="http://developer.android.com/guide/topics/manifest/activity-element.html#exclude" rel="nofollow noreferrer">android:excludeFromRecents</a> if you don't want your app start from recent apps</p> <p><a href="http://developer.android.com/guide/topics/manifest/activity-element.html#finish" rel="nofollow noreferrer">android:finishOnTaskLaunch</a></p> <p><a href="http://developer.android.com/guide/topics/manifest/activity-element.html#state" rel="nofollow noreferrer">android:stateNotNeeded</a></p>
    singulars
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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