title: Android: Autostart app and load preferences
body: <p>I have a problem with initializing my app properly after the autostart.</p>
  
  <p>I've managed to get an autostart to work, after a reboot the app is shown as started but the timer's are not.
  My guess is that the "onCreate" function of MyApp is not called when I call the context.startService(). The timers are set in the doActivity() function of MyApp.</p>
  
  <p>I would greatly appreciate any tips on what I could be doing wrong or links to good tutorials. :)</p>
  
  <p>The <strong>manifest</strong>:</p>
  
  <pre><code>    &lt;activity android:name=".MyApp"
                android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;receiver android:name="MyApp_Receiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;[/syntax]
  </code></pre>
  
  <p><strong>MyApp_Receiver</strong> is a BoradcastReciever with the following two functions</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
      // Do Autostart if intent is "BOOT_COMPLETED"
      if ((intent.getAction() != null) &amp;&amp; (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
      {
          // Start the service
          context.startService(new Intent(context, MyApp.class));
      }
      // Else do activity
      else
          MAIN_ACTIVITY.doActivity();
  }
  
  public static void setMainActivity(MyApp activity)
  {
      MAIN_ACTIVITY = activity;
  }
  </code></pre>
  
  <p><strong>MyApp</strong> extends PreferenceActivity and has an onCreate() and a doActivity(), the doActivity() reads out the preferences and sets a timer depending on them.</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // Show preferences
      addPreferencesFromResource(R.xml.preferences);;
  
      // Register Preference Click Listeners
      getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
  
  
      // Prepare for one-shot alarms
      if (mIntent == null)
      {
          mIntent = new Intent(MyApp.this, MyApp_Receiver.class);
          mSender = PendingIntent.getBroadcast(MyApp.this,
                  0, mIntent, 0);
          MyApp_Receiver.setMainActivity(this);
      }
  
      // Refresh and set all timers on start
      doActivity();
  }
  </code></pre>