Note that there are some explanatory texts on larger screens.

plurals
  1. POlaunchModes, singleTask: how to switch between "screens"? Is Intents the only way, and if so I think I have a problem
    primarykey
    data
    text
    <p>In a number of questions (<a href="https://stackoverflow.com/questions/2013865/header-views-and-buttons-how-do-i-attach-listeners-to-buttons-in-a-header-th">like this one</a>) I have been looking into how to "change screens" in my app. I have a "header" on top, with 4 buttons. Each button is meant to replace the "content" (ie change screen):</p> <pre><code>+--------------------+ | menu with buttons | +--------------------+ | | | | | C O N T E N T | | | | | +--------------------+ </code></pre> <p>When I click a Menu button, I run the following code:</p> <pre><code>@Override public void onClick(View v) { Intent myIntent = new Intent(BaseActivity.this, ActivityMain.class); BaseActivity.this.startActivity(myIntent); } </code></pre> <p>As you can see, the <i>startActivity</i> is executed. Now, if I do not specify <i>"launchMode"</i> for the Activity that means that launchMode = normal. If launchMode == normal that means that the Activity will be re-created each and every time I navigate using the top header buttons, and that means that all data entered in "form elements" are gone (or at least hidden).</p> <p>So, I found the launchMode "singleTask" that sounded sort of nice. If I add that launchMode to my Activity, it will not be re-created when I navigate with the buttons, thus keeping state. Great! Well, until I read <a href="http://developer.android.com/guide/topics/fundamentals.html#acttask" rel="nofollow noreferrer">this</a>:</p> <p><i>As noted above, there's never more than one instance of a "singleTask" or "singleInstance" activity, so that instance is expected to handle all new intents.</i></p> <p>I found out that the sentence mean that <b>there can be only one</b> Activity that has the launchMode set to "singleTask" - if I have more than one it wont work (no compiler error though). </p> <p><b>This means that I can only "keep the state" for one Activity, when switching back and forth (navigating) between my screens!</b></p> <p><a href="https://stackoverflow.com/questions/2032173/configuration-changed-orientation-change-and-destroying-activities-is-this-th">Once again</a>, is this really how it supposed to work?</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.
 

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