Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When are @InjectView fields injected?

Exactly when are an Activity's fields that are annotated with @InjectView or @InjectResource injected?

like image 413
Jeff Axelrod Avatar asked Apr 04 '12 20:04

Jeff Axelrod


1 Answers

According to A Simple Example on Roboguice's website, the members are populated by the time super.onCreate() has been called from the Activity's onCreate() method:

class RoboWay extends RoboActivity { 
    @InjectView(R.id.name)             TextView name; 
    @InjectView(R.id.thumbnail)        ImageView thumbnail; 
    @InjectResource(R.drawable.icon)   Drawable icon; 
    @InjectResource(R.string.app_name) String myName; 
    @Inject                            LocationManager loc; 

    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);
        name.setText( "Hello, " + myName ); 
    } 
}
like image 141
Jeff Axelrod Avatar answered Nov 14 '22 23:11

Jeff Axelrod