Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid LifeCycle for Activities and thei subcomponents
    primarykey
    data
    text
    <p>I get from time to time in my app the following stacktrace from a crash:</p> <pre><code>java.lang.IllegalStateException: System services not available to Activities before onCreate() at android.app.Activity.getSystemService(Activity.java:4463) at android.widget.ArrayAdapter.init(ArrayAdapter.java:310) at android.widget.ArrayAdapter.&lt;init&gt;(ArrayAdapter.java:128) at org.MyCommands.initCommands(FICSCommands.java:78) at org.MyCommands.MyFragementActivity.onStart(ConsoleTriangle.java:90) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164) at android.app.Activity.performStart(Activity.java:5114) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2273) </code></pre> <p>According to the <a href="http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle" rel="nofollow">Activity Lifecyle</a> the <code>onCreate()</code> is BEFORE the <code>onStart()</code> and I guess, that applies as well for <code>FragmentActivity</code>. So I conclude that everything which is required for the <code>onStart()</code> is already done and available. But according to the stacktrace that's not the case. I wanna initiate some ArrayAdapter, but this fails. <code>:(</code> </p> <p>The exception happens, when the app was in the background, I activate it and it comes to the foreground. I guess it is also related with that it was toooo long in the background and therefore some stuff was already GCed. </p> <p>Any ideas how I can check the things properly?</p> <p><strong>EDIT:</strong> <em>(due to the questions, to make it little bit more clear what I am asking about)</em></p> <p>What I did up till now is something like this:</p> <pre><code>oncreate() MyFragementActivity msgText = ... .... onStart() msgText.initCommands(this) </code></pre> <p>and in MyFragementActivity</p> <pre><code>initCommands(View v) ... ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(InitialContext.getContext(),... </code></pre> <p>I changed it now into</p> <pre><code> ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(v,... </code></pre> <p>But what I still do not understand:</p> <ol> <li>Normally it works, why does it fail from time to time?</li> <li>What is the difference between using the intial context from the Activity instead of the View where the components are layed out?</li> <li>How to test it? I mean, the problem occured sporadically, with no idea <em>Why?</em> Therefore I would appreciate if I could if the change really fixes the issue (or not).</li> </ol>
    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.
    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