Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: activity performing unwanted function during onResume()
    primarykey
    data
    text
    <p>I'm making an app with a splashscreen animation. I have given the user the option of canceling the animation. </p> <p>The home screen (Home) has a TextView (tv) . I set the text during the onCreate(), and again during the onResume() .</p> <p>When running with the animation, the flow is: splashscreen -> home screen -> other activities. The text of tv is set, and then returning to the home screen it 'reloads' and sets different text.</p> <p>When the animation is canceled, it starts with the home screen: home screen -> other activities.</p> <p>THE PROBLEM: When animation is canceled, the home screen sets the text in tv2 during the onCreate() and then SETS IT AGAIN in the onResume(), even though I have added an 'if' clause to prevent this from happening.</p> <p>Here is come code:</p> <pre><code>public class Home extends Activity { public static boolean reload = true; EditText tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv= (EditText) findViewById(R.id.textViewFact); tv.setText(updateText()); MORE STUFF .... } </code></pre> <p>The 'reload' is set to false from a different activity, if the user chooses to cancel the animation.</p> <p>and now for the onResume:</p> <pre><code>public void onResume(){ super.onResume(); Log.i("test", "home activity before if: " + Home.reload); if(!reload){ Log.i("test", "home activity inside if: " + Home.reload); return; } else{ Log.i("test", "home activity inside else: " + Home.reload); tv.setText(updateText()); } } </code></pre> <p>As you can see, the updateText() runs in the onCreate() and the onResume(), yet if reload is false (which it IS, as you can see in the following logcat output), it SHOULD NOT be running the updateText() again.</p> <pre><code>01-30 08:44:50.140: I/test(551): home activity before if: false 01-30 08:44:50.140: I/test(551): home activity inside if: false 01-30 08:44:51.170: I/test(551): home activity before if: false 01-30 08:44:51.170: I/test(551): home activity inside if: false </code></pre> <p>I don't know why it is getting into the onResume() TWICE (which it is, by the log output), and how it is even running the updateText() function, when that is only inside the ELSE clause, which isn't reached, according to the log output.</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.
 

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