Tabnine Logo
SpiceManager
Code IndexAdd Tabnine to your IDE (free)

How to use
SpiceManager
in
com.octo.android.robospice

Best Java code snippets using com.octo.android.robospice.SpiceManager (Showing top 20 results out of 315)

origin: com.octo.android.robospice/robospice

@Override
public final void onDestroy() {
  spiceManager.shouldStop();
  super.onDestroy();
}
origin: com.octo.android.robospice/robospice

@Override
protected void onStart() {
  spiceManager.start(this);
  super.onStart();
}
origin: stackoverflow.com

 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;
  }

}
origin: com.octo.android.robospice/robospice

private boolean tryToStartService() {
  boolean success = false;
  // start the service it is not started yet.
  Context context = getContextReference();
  if (context != null) {
    checkServiceIsProperlyDeclaredInAndroidManifest(context);
    final Intent intent = new Intent(context, spiceServiceClass);
    context.startService(intent);
    success = true;
  }
  return success;
}
origin: com.octo.android.robospice/robospice

/**
 * Execute a request, without using cache. No result from cache will be
 * returned. The method {@link SpiceRequest#loadDataFromNetwork()} will
 * always be invoked. The result will not be stored in cache.
 * @param request
 *            the request to execute.
 * @param requestListener
 *            the listener to notify when the request will finish.
 */
public <T> void execute(final SpiceRequest<T> request, final RequestListener<T> requestListener) {
  final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, null, DurationInMillis.ALWAYS_RETURNED);
  execute(cachedSpiceRequest, requestListener);
}
origin: com.octo.android.robospice/robospice

@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());
  }
}
origin: com.octo.android.robospice/robospice

@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.");
}
origin: n76/wifi_backend

@Override
public void onStart() {
  super.onStart();
  if(!hasStartedRequest) {
    getSpiceManager().execute(getRequest(), getCacheKey(), DurationInMillis.ALWAYS_EXPIRED, this);
    hasStartedRequest = true;
  } else {
    getSpiceManager().addListenerIfPending(getRequest().getResultType(), getCacheKey(), this);
  }
}
origin: com.octo.android.robospice/robospice

@Override
public void run() {
  if (!tryToStartService()) {
    Ln.d("Service was not started as Activity died prematurely");
    isStopped = true;
    return;
  }
  bindToService();
  try {
    waitForServiceToBeBound();
    if (spiceService == null) {
      Ln.d("No spice service bound.");
      return;
    }
    while (!requestQueue.isEmpty() || !isStopped && !Thread.interrupted()) {
      try {
        sendRequestToService(requestQueue.take());
      } catch (final InterruptedException ex) {
        Ln.d("Interrupted while waiting for new request.");
        // we receive an interrupted exception while waiting
        // see java spec : http://stackoverflow.com/a/6699006/693752
        break;
      }
    }
    Ln.d("SpiceManager request runner terminated. Requests count: %d, stopped %b, interrupted %b", requestQueue.size(), isStopped, Thread.interrupted());
  } catch (final InterruptedException e) {
    Ln.d(e, "Interrupted while waiting for acquiring service.");
  }
}
origin: com.octo.android.robospice/robospice

/**
 * Add listener to a pending request if it exists. If no such request
 * exists, this method calls onRequestNotFound on the listener. If a request
 * identified by clazz and requestCacheKey, it will receive an additional
 * listener.
 * @param clazz
 *            the class of the result of the pending request to look for.
 * @param requestCacheKey
 *            the key used to store and retrieve the result of the request
 *            in the cache
 * @param requestListener
 *            the listener to notify when the request will finish.
 */
public <T> void addListenerIfPending(final Class<T> clazz, final Object requestCacheKey, final PendingRequestListener<T> requestListener) {
  addListenerIfPending(clazz, requestCacheKey, (RequestListener<T>) requestListener);
}
origin: com.octo.android.robospice/robospice

/**
 * Execute a request, put the result in cache and register listeners to
 * notify when request is finished.
 * @param cachedSpiceRequest
 *            the request to execute. {@link CachedSpiceRequest} is a
 *            wrapper of {@link SpiceRequest} that contains cache key and
 *            cache duration
 * @param requestListener
 *            the listener to notify when the request will finish
 */
public <T> void execute(final CachedSpiceRequest<T> cachedSpiceRequest, final RequestListener<T> requestListener) {
  addRequestListenerToListOfRequestListeners(cachedSpiceRequest, requestListener);
  Ln.d("adding request to request queue");
  this.requestQueue.add(cachedSpiceRequest);
}
origin: com.octo.android.robospice/robospice

/**
 * Execute a request. Before invoking the method
 * {@link SpiceRequest#loadDataFromNetwork()}, the cache will be checked :
 * if a result has been cached with the cache key <i>requestCacheKey</i>,
 * RoboSpice will consider the parameter <i>cacheExpiryDuration</i> to
 * determine whether the result in the cache is expired or not. If it is not
 * expired, then listeners will receive the data in cache. Otherwise, the
 * method {@link SpiceRequest#loadDataFromNetwork()} will be invoked and the
 * result will be stored in cache using the cache key
 * <i>requestCacheKey</i>.
 * @param request
 *            the request to execute
 * @param requestCacheKey
 *            the key used to store and retrieve the result of the request
 *            in the cache
 * @param cacheExpiryDuration
 *            duration in milliseconds after which the content of the cache
 *            will be considered to be expired.
 *            {@link DurationInMillis#ALWAYS_RETURNED} means data in cache
 *            is always returned if it exists.
 *            {@link DurationInMillis#ALWAYS_EXPIRED} means data in cache is
 *            never returned.(see {@link DurationInMillis})
 * @param requestListener
 *            the listener to notify when the request will finish
 */
public <T> void execute(final SpiceRequest<T> request, final Object requestCacheKey, final long cacheExpiryDuration, final RequestListener<T> requestListener) {
  final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, requestCacheKey, cacheExpiryDuration);
  execute(cachedSpiceRequest, requestListener);
}
origin: com.octo.android.robospice/robospice

/**
 * @See #addListenerIfPending(Class, Object, PendingRequestListener)
 */
@Deprecated
public <T> void addListenerIfPending(final Class<T> clazz, final Object requestCacheKey, final RequestListener<T> requestListener) {
  final SpiceRequest<T> request = new SpiceRequest<T>(clazz) {
    @Override
    public T loadDataFromNetwork() throws Exception {
      return null;
    }
  };
  final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, requestCacheKey, DurationInMillis.ALWAYS_EXPIRED);
  cachedSpiceRequest.setProcessable(false);
  execute(cachedSpiceRequest, requestListener);
}
origin: com.octo.android.robospice/robospice

@Override
protected void onStop() {
  spiceManager.shouldStop();
  super.onStop();
}
origin: com.octo.android.robospice/robospice-sample

@Override
protected void onStart() {
  contentManagerJson.start( this );
  contentManagerOrmlite.start( this );
  super.onStart();
}
origin: stackoverflow.com

private SpiceManager spiceManager = new SpiceManager(CustomSpiceService.class);
origin: com.octo.android.robospice/robospice-sample

@Override
protected void onStart() {
  super.onStart();
  getJsonContentManager().execute(loremRequest, "lorem.txt", DurationInMillis.ONE_DAY, new LoremRequestListener());
  getJsonContentManager().execute(weatherRequest, "75000.json", DurationInMillis.ONE_DAY, new WeatherRequestJsonListener());
  getJsonContentManager().execute(weatherRequestXml, "75000.xml", DurationInMillis.ONE_DAY, new WeatherRequestXmlListener());
  getJsonContentManager().execute(imageRequest, "logo", DurationInMillis.ONE_DAY, new ImageRequestListener());
}
origin: com.octo.android.robospice/robospice

@Override
public final void onDestroy() {
  spiceManager.shouldStop();
  super.onDestroy();
}
origin: n76/wifi_backend

@Override
public void onStart() {
  super.onStart();
  spiceManager.start(getActivity());
}
origin: stackoverflow.com

public static SpiceManager spiceManager = new SpiceManager(SpiceService.class);
com.octo.android.robospiceSpiceManager

Javadoc

The instances of this class allow to acces the SpiceService.
They are tied to activities and obtain a local binding to the SpiceService. When binding occurs, the SpiceManager will send commadnds to the SpiceService, to execute requests, clear cache, prevent listeners from being called and so on. Basically, all features of the SpiceService are accessible from the SpiceManager. It acts as an asynchronous proxy : every call to a SpiceService method is asynchronous and will occur as soon as possible when the SpiceManagersuccessfully binds to the service.

Most used methods

  • execute
  • shouldStop
    Stops the SpiceManager. It will unbind from SpiceService. All request listeners that had been regist
  • start
    Start the SpiceManager. It will bind asynchronously to the SpiceService.
  • <init>
    Creates a SpiceManager. Typically this occurs in the construction of an Activity or Fragment. This m
  • addListenerIfPending
  • addRequestListenerToListOfRequestListeners
  • addSpiceServiceListener
  • bindToService
  • checkServiceIsProperlyDeclaredInAndroidManifest
  • dontNotifyAnyRequestListenersInternal
    Remove all listeners of requests. All requests that have not been yet passed to the service will see
  • dontNotifyRequestListenersForRequestInternal
    Internal method to remove requests. If request has not been passed to the SpiceService yet, all list
  • executeCommand
  • dontNotifyRequestListenersForRequestInternal,
  • executeCommand,
  • getContextReference,
  • getThreadCount,
  • isStarted,
  • match,
  • putInCache,
  • removeListenersOfAllPendingCachedRequests,
  • removeListenersOfCachedRequestToLaunch,
  • removeListenersOfPendingCachedRequest

Popular in Java

  • Creating JSON documents from java classes using gson
  • getSupportFragmentManager (FragmentActivity)
  • getResourceAsStream (ClassLoader)
  • scheduleAtFixedRate (Timer)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now