public class MyApplication extends Application { private static MyApplication instance; private SpiceManager spiceManager = new SpiceManager(RequestService.class); @Override public void onCreate() { super.onCreate(); } public SpiceManager getManager() { return spiceManager; } }
public static SpiceManager spiceManager = new SpiceManager(SpiceService.class);
private SpiceManager spiceManager = new SpiceManager(CustomSpiceService.class);
public class AppSingleton extends Application{ private static AppSingleton ourInstance = new AppSingleton(); private SpiceManager spiceManager= new SpiceManager(RoboSpiceService.class); public static AppSingleton getInstance() { return ourInstance; } public SpiceManager getSpiceManager() { return spiceManager; } }
@SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) @Override public final void onStart(final Intent intent, final int startId) { super.onStart(intent, startId); notificationId = intent.getIntExtra(BUNDLE_KEY_NOTIFICATION_ID, DEFAULT_ROBOSPICE_NOTIFICATION_ID); requestClass = (Class<?>) intent.getSerializableExtra(BUNDLE_KEY_REQUEST_CLASS); requestCacheKey = intent.getStringExtra(BUNDLE_KEY_REQUEST_CACHE_KEY); spiceServiceClass = (Class<? extends SpiceService>) intent.getSerializableExtra(BUNDLE_KEY_SERVICE_CLASS); if (spiceServiceClass == null) { throw new RuntimeException("Please specify a service class to monitor. Use #createIntent as helper."); } foreground = intent.getBooleanExtra(BUNDLE_KEY_FOREGROUND, true); spiceManager = new SpiceManager(spiceServiceClass); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); spiceManager.start(this); spiceManager.addListenerIfPending(requestClass, requestCacheKey, new NotificationRequestListener()); if (foreground) { startForeground(notificationId, onCreateForegroundNotification()); } }
@SuppressWarnings({ "unchecked", "deprecation" }) @Override public final void onStart(final Intent intent, final int startId) { super.onStart(intent, startId); if (intent == null) { return; } notificationId = intent.getIntExtra(BUNDLE_KEY_NOTIFICATION_ID, DEFAULT_ROBOSPICE_NOTIFICATION_ID); spiceServiceClass = (Class<? extends SpiceService>) intent.getSerializableExtra(BUNDLE_KEY_SERVICE_CLASS); if (spiceServiceClass == null) { throw new RuntimeException("Please specify a service class to monitor. Use #createIntent as helper."); } foreground = intent.getBooleanExtra(BUNDLE_KEY_FOREGROUND, true); spiceManager = new SpiceManager(spiceServiceClass); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); spiceManager.start(this); spiceManager.addSpiceServiceListener(new NotificationSpiceServiceListener()); if (foreground) { startForeground(notificationId, onCreateForegroundNotification()); } Ln.d(getClass().getSimpleName() + " started."); }