Skip to content

Instantly share code, notes, and snippets.

@janishar
Created December 25, 2016 07:51
Show Gist options
  • Save janishar/bde18926209f8c0f920ed668b180a8b1 to your computer and use it in GitHub Desktop.
Save janishar/bde18926209f8c0f920ed668b180a8b1 to your computer and use it in GitHub Desktop.
public class MainActivity extends AppCompatActivity {
@Inject
DataManager mDataManager;
private ActivityComponent activityComponent;
private TextView mTvUserInfo;
private TextView mTvAccessToken;
public ActivityComponent getActivityComponent() {
if (activityComponent == null) {
activityComponent = DaggerActivityComponent.builder()
.activityModule(new ActivityModule(this))
.applicationComponent(DemoApplication.get(this).getComponent())
.build();
}
return activityComponent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActivityComponent().inject(this);
mTvUserInfo = (TextView) findViewById(R.id.tv_user_info);
mTvAccessToken = (TextView) findViewById(R.id.tv_access_token);
}
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
createUser();
getUser();
mDataManager.saveAccessToken("ASDR12443JFDJF43543J543H3K543");
String token = mDataManager.getAccessToken();
if(token != null){
mTvAccessToken.setText(token);
}
}
private void createUser(){
try {
mDataManager.createUser(new User("Ali", "1367, Gurgaon, Haryana, India"));
}catch (Exception e){e.printStackTrace();}
}
private void getUser(){
try {
User user = mDataManager.getUser(1L);
mTvUserInfo.setText(user.toString());
}catch (Exception e){e.printStackTrace();}
}
}
@pavelupward
Copy link

DaggerActivityComponent ?error: Error:(69, 1) error: class, interface, or enum expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment