com.xtremelabs.robolectric.shadows
Class ShadowApplication

java.lang.Object
  extended by com.xtremelabs.robolectric.shadows.ShadowContext
      extended by com.xtremelabs.robolectric.shadows.ShadowContextWrapper
          extended by com.xtremelabs.robolectric.shadows.ShadowApplication

@Implements(value=android.app.Application.class)
public class ShadowApplication
extends ShadowContextWrapper

Shadows the android.app.Application class.


Nested Class Summary
 class ShadowApplication.Wrapper
           
 
Constructor Summary
ShadowApplication()
           
 
Method Summary
 void assertNoBroadcastListenersRegistered(android.content.Context context, java.lang.String type)
          Iterates through all of the registered receivers on this Application and if any of them match the given Context object throws a RuntimeException
static android.app.Application bind(android.app.Application application, com.xtremelabs.robolectric.res.ResourceLoader resourceLoader)
          Associates a ResourceLoader with an Application instance
 android.content.Context getApplicationContext()
           
 android.appwidget.AppWidgetManager getAppWidgetManager()
          Non-Android accessor.
 android.content.ContentResolver getContentResolver()
           
 android.view.LayoutInflater getLayoutInflater()
          Non-Android accessor.
 android.content.Intent getNextStartedActivity()
          Consumes the most recent Intent started by startActivity(android.content.Intent) and returns it.
 android.content.Intent getNextStartedService()
          Consumes the most recent Intent started by startService(android.content.Intent) and returns it.
 java.util.List<ShadowApplication.Wrapper> getRegisteredReceivers()
          Non-Android accessor.
 com.xtremelabs.robolectric.res.ResourceLoader getResourceLoader()
          Non-Android accessor (and a handy way to get a working ResourceLoader
 android.content.res.Resources getResources()
           
 java.lang.Object getSystemService(java.lang.String name)
           
 android.content.Intent peekNextStartedActivity()
          Returns the most recent Intent started by startActivity(android.content.Intent) without consuming it.
 android.content.Intent peekNextStartedService()
          Returns the most recent Intent started by startService(android.content.Intent) without consuming it.
 android.content.Intent registerReceiver(android.content.BroadcastReceiver receiver, android.content.IntentFilter filter)
          Always returns null
 void sendBroadcast(android.content.Intent intent)
          Broadcasts the Intent by iterating through the registered receivers, invoking their filters, and calling onRecieve(Application, Intent) as appropriate.
 void startActivity(android.content.Intent intent)
           
 android.content.ComponentName startService(android.content.Intent intent)
           
 void unregisterReceiver(android.content.BroadcastReceiver broadcastReceiver)
           
 
Methods inherited from class com.xtremelabs.robolectric.shadows.ShadowContextWrapper
__constructor__, getPackageManager, getPackageName, getSharedPreferences
 
Methods inherited from class com.xtremelabs.robolectric.shadows.ShadowContext
getString, getString, getText
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShadowApplication

public ShadowApplication()
Method Detail

bind

public static android.app.Application bind(android.app.Application application,
                                           com.xtremelabs.robolectric.res.ResourceLoader resourceLoader)
Associates a ResourceLoader with an Application instance

Parameters:
application - application
resourceLoader - resource loader
Returns:
the application todo: make this non-static?

getApplicationContext

@Implementation
public android.content.Context getApplicationContext()
Overrides:
getApplicationContext in class ShadowContextWrapper

getResources

@Implementation
public android.content.res.Resources getResources()
Overrides:
getResources in class ShadowContextWrapper

getContentResolver

@Implementation
public android.content.ContentResolver getContentResolver()
Overrides:
getContentResolver in class ShadowContextWrapper

getSystemService

@Implementation
public java.lang.Object getSystemService(java.lang.String name)
Overrides:
getSystemService in class ShadowContextWrapper

startActivity

@Implementation
public void startActivity(android.content.Intent intent)
Overrides:
startActivity in class ShadowContextWrapper

startService

@Implementation
public android.content.ComponentName startService(android.content.Intent intent)
Overrides:
startService in class ShadowContextWrapper

getNextStartedActivity

public android.content.Intent getNextStartedActivity()
Consumes the most recent Intent started by startActivity(android.content.Intent) and returns it.

Overrides:
getNextStartedActivity in class ShadowContextWrapper
Returns:
the most recently started Intent

peekNextStartedActivity

public android.content.Intent peekNextStartedActivity()
Returns the most recent Intent started by startActivity(android.content.Intent) without consuming it.

Overrides:
peekNextStartedActivity in class ShadowContextWrapper
Returns:
the most recently started Intent

getNextStartedService

public android.content.Intent getNextStartedService()
Consumes the most recent Intent started by startService(android.content.Intent) and returns it.

Overrides:
getNextStartedService in class ShadowContextWrapper
Returns:
the most recently started Intent

peekNextStartedService

public android.content.Intent peekNextStartedService()
Returns the most recent Intent started by startService(android.content.Intent) without consuming it.

Overrides:
peekNextStartedService in class ShadowContextWrapper
Returns:
the most recently started Intent

getResourceLoader

public com.xtremelabs.robolectric.res.ResourceLoader getResourceLoader()
Non-Android accessor (and a handy way to get a working ResourceLoader

Overrides:
getResourceLoader in class ShadowContext
Returns:
the ResourceLoader associated with this Application

sendBroadcast

@Implementation
public void sendBroadcast(android.content.Intent intent)
Broadcasts the Intent by iterating through the registered receivers, invoking their filters, and calling onRecieve(Application, Intent) as appropriate. Does not enqueue the Intent for later inspection.

Overrides:
sendBroadcast in class ShadowContextWrapper
Parameters:
intent - the Intent to broadcast todo: enqueue the Intent for later inspection

registerReceiver

@Implementation
public android.content.Intent registerReceiver(android.content.BroadcastReceiver receiver,
                                                              android.content.IntentFilter filter)
Always returns null

Overrides:
registerReceiver in class ShadowContextWrapper
Returns:
null

unregisterReceiver

@Implementation
public void unregisterReceiver(android.content.BroadcastReceiver broadcastReceiver)
Overrides:
unregisterReceiver in class ShadowContextWrapper

assertNoBroadcastListenersRegistered

public void assertNoBroadcastListenersRegistered(android.content.Context context,
                                                 java.lang.String type)
Iterates through all of the registered receivers on this Application and if any of them match the given Context object throws a RuntimeException

Parameters:
context - the Context to check for on each of the remaining registered receivers
type - the type to report for the context if an exception is thrown
Throws:
java.lang.RuntimeException - if there are any recievers registered with the given Context

getRegisteredReceivers

public java.util.List<ShadowApplication.Wrapper> getRegisteredReceivers()
Non-Android accessor.

Returns:
list of ShadowApplication.Wrappers for registered receivers

getLayoutInflater

public android.view.LayoutInflater getLayoutInflater()
Non-Android accessor.

Returns:
the layout inflater used by this Application

getAppWidgetManager

public android.appwidget.AppWidgetManager getAppWidgetManager()
Non-Android accessor.

Returns:
the app widget manager used by this Application