My android service causes the app to crash
<p>I'm trying to call a method of another class but this causes my app to crash.</p>

<p>This is what I'm doing to run it on boot</p>

<pre><code>public class BootReceiver extends BroadcastReceiver{

   @Override
   public void onReceive(Context context, Intent intent) {
          MyApp test = new MyApp();
          test.run_service();
   }
}
</code></pre>

<p>I've commented out all the lines from run_service() to find out what the cause is, and it's this line</p>

<pre><code>SharedPreferences settings = getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
</code></pre>

<p>It works fine if I call it from within that class (when the application is the foreground), so why can't I call it from inside onReceieve?</p>

<p>Updated to add notification code:</p>

<pre><code>CharSequence title = "MyApp";
CharSequence message = "Hello World";

NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.icon, "Hi!", System.currentTimeMillis());

Intent notificationIntent = new Intent(context, MyApp.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
n.setLatestEventInfo(MyApp.this, title, message, pendingIntent);
nm.notify(NOTIFICATION_ID, n);
</code></pre>
