Hi Shephertz,
I am trying to get username of person who have logged in. but unable t get it. please check the following code, for this i have followed your SampleAPITest example.
Dashboard.java
private TextView tv;
private AsyncApp42ServiceApi asyncService;
private String userName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
asyncService = AsyncApp42ServiceApi.instance();
asyncService.getUser(userName, this);
tv = (TextView) findViewById(R.id.username);
@Override
public void onGetUserSuccess(User response) {
String userName = response.getUserName();
tv.setText(userName);
}
@Override
public void onGetUserFailed(App42Exception exception) {
// TODO Auto-generated method stub
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
AsyncApp42ServiceApi.java
public class AsyncApp42ServiceApi {
private UserService userService;
private StorageService storageService;
private UploadService uploadService;
private ScoreBoardService scoreBoardService;
private static AsyncApp42ServiceApi mInstance = null;
private AsyncApp42ServiceApi() {
ServiceAPI sp = new ServiceAPI(Constants.App42ApiKey,
Constants.App42ApiSecret);
this.userService = sp.buildUserService();
}
public static AsyncApp42ServiceApi instance() {
if (mInstance == null) {
mInstance = new AsyncApp42ServiceApi();
}
return mInstance;
}
public void getUser(final String name, final App42UserServiceListener callBack) {
final Handler callerThreadHandler = new Handler();
new Thread() {
@Override
public void run() {
try {
final User response = userService.getUser(name);
callerThreadHandler.post(new Runnable() {
@Override
public void run() {
callBack.onGetUserSuccess(response);
}
});
} catch (final App42Exception ex) {
callerThreadHandler.post(new Runnable() {
@Override
public void run() {
if (callBack != null) {
callBack.onGetUserFailed(ex);
}
}
});
}
}
}.start();
}
public static interface App42UserServiceListener {
public void onGetUserSuccess(User response);
public void onGetUserFailed(App42Exception exception);
}
}